共 16 篇文章 |
|
假如a="one,two,three,four"要将$a分割开,可以这样:OLD_IFS="$IFS" IFS="," arr=($a) IFS="$OLD_IFS" for s in ${arr[@]} do echo "$s" done上述代码会输出one two three fourarr=($a)用于将字符串$a分割到数组$arr ${arr[0]} ${arr[1]} ...分别存储分割后的数组第1 2 ...项 ,${arr[... 阅1743 转5 评0 公众公开 16-06-17 11:49 |
阅355 转2 评0 公众公开 14-12-13 10:08 |
进程ID变量,这个变量保存了运行当前脚本的进程ID值。tar.bz2 | tar xvf - ##将前面解压的数据作为tar的标准输入##(这里使用一个-表示)注意:在实作的时候,如果文件名是以[-]开头的,那么在加上这个作为定向操作符的时候,可能会出错,此时应该为文件加上合适的前缀路径,以避免这种情况发生,同样的,在echo变量的时候,如果变量是以[-]开... 阅4128 转33 评0 公众公开 14-11-27 14:52 |
shell字符串的截取。[chengmo@localhost ~]$ test=''c:/windows/boot.ini''[chengmo@localhost ~]$ echo ${test#/}c:/windows/boot.ini[chengmo@localhost ~]$ echo ${test#*/}windows/boot.ini[chengmo@localhost ~]$ echo ${test##*/}boot.ini.[chengmo@localhost ~]$ test=''c:/windows/boot.ini''[chengmo... 阅142 转4 评0 公众公开 14-11-25 14:20 |
使用shell脚本将一整个目录的apk都安装到手机中#!/bin/bashfiles=$(ls | grep .apk)for file in $filesdo echo $file adb install -r $filedone. 阅152 转1 评0 公众公开 14-11-24 17:58 |
五种方法实现Linux批量重命名文件。Linux批量重命名文件会涉及到改变一个字母、改变一些相连字母、改变某些位置的字母、在最前面加上某些字母、或者改变字母的大小写。 阅127 转1 评0 公众公开 13-12-10 10:31 |
bash: No such file or directory 错误原因总结。-bash: ***: No such file or directory.1. bash script出现该错误:$ ./gcc-bash: ./gcc: No such file or directory$ scp ***tmp/a.out ./a.out 100% 9037 8.8KB/s 00:00$ ./a.out-bash: ./a.out: No such file or directo... 阅26637 转7 评0 公众公开 13-06-16 22:48 |
shell数组用法Shell编程_$#输入参数的个数_${#arrayname[@]}数组元素的个数_$arrayname[index]数组中的某一个成员_获取数组中的所有元素${arrayname[*]}shell中定义一个数组:获取数组元素的个数:那么${#arrayname[@]}表示数组中元素的个数。那么${#value}表示数组中元素的个数。那么同样的道理,要获取数组中某个变量的长度: 阅407 转2 评0 公众公开 13-05-24 15:38 |
代码: ls my_{finger,toe}s这条命令相当于如下命令的组合: ls my_fingers my_toes mkdir {userA,userB,userC}-{home,bin,data}代码: $ heyyou=home $ echo ''$heyyou'' $ $heyyou ($没有转义) eg: $ heyyou=home $ echo "$heyyou" $ home (很明显,$转义了输出了heyyou变量的值... 阅524 转自waston 公众公开 13-05-24 13:10 |
4,几种特殊的替换结构:${var:-string},${var:+string},${var:=string},${var:?string}6.四种模式匹配替换结构:${var%pattern},${var%%pattern},${var#pattern},${var##pattern}这四种结构的意义是:${var%pattern}和${var%%pattern}表示从最右边(即结尾)匹配的,${var#pattern} 和${var##pattern}从最左边(即开头)匹配的。其中${var%pattern}... 阅2047 转9 评0 公众公开 13-05-24 12:43 |