共 12 篇文章 |
|
为何bash中一条命令的输出保存到变量之后换行符变成了空格?在 bash 中,为了将一个命令的输出保存到变量中,通常是两种写法:result=$(ls -al)如果命令中的输出只有一行,一切皆没有问题,比如。<span></span>result=$(ls -al)echo $result<span></span>发现输出的结果中,换行符被替换成了空格,一个多行的输出变成... 阅200 转0 评0 公众公开 14-04-24 14:03 |
阅571 转1 评0 公众公开 14-02-14 15:52 |
v*}var1 var2 var3.[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@... 阅80 转0 评0 公众公开 14-02-11 11:02 |
var1="hello"var2="he"#方法1if [ ${var1:0:2} = $var2 ]then.#方法2echo "$var1" |grep -q "$var2"if [ $? -eq 0 ]then.#方法3echo "$var1" |grep -q "$var2" &&echo "include" ||echo "not"#方法4[[ "${var1/$var2/}" != "$var2&qu... 阅2353 转0 评0 公众公开 14-02-11 10:49 |
逐行读取文本文件的 shell 脚本。$ vi testfilels -a -l /bin | sortls -a -l /bin | sort | wcls -a -l | grep sh | wcls -a -lls -a -l | sort | wc.[root@localhost]# bash 1.shls -a -l /bin | sort | wcls -a -l | grep sh | wcls -a -lls -a -l | sort | wc.[root@localhost]# more datafile.txtls -a -l /bin | sort | wcls -a -l | gre... 阅3447 转2 评0 公众公开 14-02-11 10:31 |
换句话说,set 变量里包含了 env 变量,但 set 变量不一定都是 env 变量。如果此时 echo $var,则需要在这些变量之间用空格隔开,也就是"" [space] " a" [space] "b" [space] ""[space] "c" ,忽略掉空值,最终输出是 [space][space]a[space]b[space][space]c !$ IFS=: $ var=ab::c... 阅299 转1 评0 公众公开 14-01-13 15:15 |