来源:自学PHP网 时间:2015-04-14 10:17 作者: 阅读:次
[导读] 文章来源: (linux shell)第一章--小试牛刀(下)1 6 数组和关联数组 1 6 1 预备知识 Bash同时支持普通数组和关联数组,普通数组只能使用整数作为数组索引,而关联数组可以使用字...
文章来源:
(linux shell)第一章--小试牛刀(下) 1.6 数组和关联数组 1.6.1 预备知识 Bash同时支持普通数组和关联数组,普通数组只能使用整数作为数组索引,而关联数组可以使用字符串作为数组索引。关联数组在很多操作中相当有用。 1.6.2 实战演练 定义数组的方法有很多,可以在单行中使用一列值来定义一个数组: array_var=(1,2,3,4,5,6) #这些值将会存储在以0为起始索引的连续位置上 另外,还可以将数组定义成一组索引-值: array_var[0]="test1" array_var[1]="test2" 打印出特定数组元素的内容: echo ${array_var[0]} 以清单形式打印出数组中的所有值: echo ${array_var[*]} 打印数组长度 echo ${#array_var[*]} 1.7 使用别名 1.7.1 预备知识 别名有多种便捷方式,可以使用函数,也可以使用alias命令 1.7.2 实战演练 alias new_command='command sequence' alias install='sudo apt-get install' 当然,这样修改的别名只是暂时的,只对当前终端有效,如果想一直保持作用,可将它放入~/.bashrc中 1.8 获取终端信息 1.8.1 预备只是 tput和stty是两款终端处理工具。 1.8.2 实战演练 获取终端的行数和列数 tput cols tpu lines 打印出当前终端名称:<喎"http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+ICAgICAgICB0cHV0IGxvbmduYW1lPC9wPgo8cD4gICAgICAgIL2rueKx6tLGtq+1vbe9zrsoMTAwLDEwMCm0pjwvcD4KPHA+ICAgICAgICB0cHV0IGN1cCAxMDAgMTAwPC9wPgo8cD4gICAgICAgIMno1sPW1bbLsbO+sMmrPC9wPgo8cD4gICAgICAgIHRwdXQgc2V0YiBubygwLS03KTwvcD4KPHA+ICAgICAgICDJ6NbDzsSxvtH5yr3OqrTWzOU6PC9wPgo8cD4gICAgICAgIHRwdXQgYm9sZDwvcD4KPHA+ICAgICAgICDJvrP9tbHHsLniseq1vdDQzrK1xMv509DE2sjdo7o8L3A+CjxwPiAgICAgICAgdHB1dCBlZDwvcD4KPHA+ICAgICAgICA8L3A+CjxwPiAgICAgICAgyrnTw3N0dHkgLWVjaG8gv8nS1NL+stjTw7unyuTI67XExNrI3TwvcD4KCjxwPjEuOSC78cihyejWw8jVxtq6zdHTyrE8L3A+CjxwPiAgICAxLjkuMSDKtdW90d3BtzwvcD4KPHA+ICAgICAgICC2wcihyNXG2qO6ICAgPGJyPgo8L3A+CjxwPiAgICAgICAgZGF0ZTwvcD4KPHA+ICAgICAgICC08tOhvM3UqsqxPC9wPgo8cD4gICAgICAgIGRhdGUgJiM0MzslczwvcD4KPHA+ICAgICAgICDRoc/uLS1kYXRl08PT2szhuanI1cbatK7X986qyuTI66GjtavO0sPHv8nS1Mq508PIztLitcTI1cbaJiMyNjY4NDvKvbuv0aHP7sC0tPLTocrks/aho72ryNXG2rSu1/fOqsrkyOvE3Lm7uf3Tw8C0u/HWqrj4tqi1xMjVxtrKx9DHxtq8uDwvcD4KPHA+ICAgICAgICBkYXRlIC0tZGF0ZSA="Jan 20 2011' +%A
可以按照你的选择打印出日期格式: date "+%d %B %Y" 时间的延时可以用sleep se╧y"http://www.2cto.com/kf/yidong/wp/" target="_blank" class="keylink">WPD/MHuPC9wPgoKPHA+MS4xMCAguq/K/brNss7K/TwvcD4KPHA+ICAgIDEuMTAuMSAgyrXVvdHdwbc8L3A+CjxwPiAgICAgICAgtqjS5bqvyv2jujwvcD4KPHA+ICAgICAgICBmdW5jdGlvbiBmbmFtZSgpIHs8L3A+CjxwPiAgICAgICAgICAgIHN0YXRlbWVudHM7PGJyPgo8L3A+CjxwPiAgICAgICAgfSAgICAgICA8L3A+CjxwPiAgICAgICAgu/LV32ZuYW1lKCl7c3RhdG1lbnRzfTwvcD4KPHA+ICAgICAgICDWu9Do0qrKudPDxLO49rqvyv3D+77Nv8nS1LX308O6r8r9OjwvcD4KPHA+ICAgICAgICBmbmFtZTwvcD4KPHA+ICAgICAgICC199PDuq/K/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AgID8gICAgP1sgLXcgJHZhciBdICAgI8jnufu4+LaotcSx5MG/sPy6rLXExNrI3b/J0LSjrNTyt7W72NXmPC9wPgo8cD4gICAgPyAgICA/WyAtZCAkdmFyIF0gICAgI8jnufu4+LaotcSx5MG/sPy6rLXExNrI3b/JtsGjrNTyt7W72NXmPC9wPgo8cD4gICAgPyAgICA/WyAtbCAkdmFyIF0gICAgICPI57n7uPi2qLXEseTBv7D8uqy1xMrH0ru49rf7usXBtL3To6zU8re1u9jV5jwvcD4KPHA+ICAgID8gICAgPzxpbWcgc3JjPQ=="http://www.2cto.com/uploadfile/Collfiles/20140726/20140726090826107.png" title="2014-07-25-105420_485x126_scrot.png" alt=""> ? ?字符串比较: ? ? ?可以检查两个字符串是否相等以及不相等: ? ? ?[[ $str1 = $str2 ]] [[ $str1 != $str2 ]] ? ? ?比较两个字符串之间的大小: ? ? ?[[ $str1 > $str2 ]] 或者 [[ $str1 < $str2 ]] ? ? ?[[ -z $str1 ]] 如果str1是空字符串,则返回真 ? ? ?[[ -n $str1 ]] 如果str1是非空字符串,则返回真? |
自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习
京ICP备14009008号-1@版权所有www.zixuephp.com
网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com