www.rtmj.net > shEll变量加字符串
shEll变量加字符串
|
字符串最好放到双引号中,防止中间有空格,如name中就可能存在空格.改为:total="${name}""${email}""${other}"或者 total="$name""$email""$other"
你的pretime1, pretime2和NE值都是什么?你可以先把它们打印出来看看或者你可以先输出 echo "ls -la | grep ${pretime1}-${pretime2}_$NE:1003"然后在命令行里面手工执行一下看看是什么结果
如果你用的是bash, 可以echo ${!cx_e}也可以eval echo \$$cx_e
不能这样写 "${TN3RD_$(echo ${library} | tr '[a-z]' '[A-Z]')_SUPPORT}"直接写:if [ "$library" == "zlib" ];then echo "${library} is included"fi
直接加在后面,但是注意如果是变量,则:[root@localhost ~]# a="123123123"[root@localhost ~]# echo $aaaa[root@localhost ~]# echo ${a}aaa123123123aaa变量最好用{}包含起来,已确保变量名
比如变量是str str="this is a string" 要想在判断str中是否含有"this"这个字符串,下面的语句是
数字和字符串不用区分,都当字符串.digit=1234;string="abcd"mix_str=$string$digit
比如变量是str str="this is a string" 要想在判断str中是否含有"this"这个字符串,下面的语句是可行的 [[ $str =~ "this" ]] && echo "\$str contains this" [[ $str =~ "that" ]] || echo "\$str does NOT contain this" 其实这里就是用到了"[[" 判断命令和 "=~"正则式匹配符号
$ echo "我们是一家人" | sed 's/是/&幸福的/' 我们是幸福的一家人
${#变量名}将字符串保存在变量中,在变量名前加#号,放入花括号中,前面加上取变量值符号$,可以返回字符串长度
All rights reserved Powered by www.rtmj.net
copyright ©right 2010-2021。