shell脚本编程中常见的一些问题



如果要比较的字符串中间有空格,可以用下面的程序(摘自《Unix Shells by Example, 3rd Edition》)

name="Joe Blow"

if [[ $name == "Joe Blow" ]]

then

     printf "Hello $name\n"

fi

如果不带空格,则可以用下面的程序

name="Joe"

if [ $name = "Joe" ]

then

     printf "Hello $name\n"

fi

需要注意的是方括号和等号的数目。

猜你喜欢

转载自blog.csdn.net/weixin_42155195/article/details/80691523