当前位置: 技术问答>linux和unix
刚学Shell编程,问个关于Shell中if语句的问题
来源: 互联网 发布时间:2016-09-09
本文导语: #!/bin/bash if["${1##*.}" = "tar"];then echo "This appears to be a tarball." else echo "at first glance,this doesn't appear to be a tarball." fi 这个程序错在哪里? 我运行时来出现 ./mytar.sh: line 3: syntax error n...
#!/bin/bash
if["${1##*.}" = "tar"];then
echo "This appears to be a tarball."
else
echo "at first glance,this doesn't appear to be a tarball."
fi
这个程序错在哪里?
我运行时来出现
./mytar.sh: line 3: syntax error near unexpected token `then'
./mytar.sh: line 3: `if["${1##*.}" = "tar"];then'
求高人指点一二。。。
if["${1##*.}" = "tar"];then
echo "This appears to be a tarball."
else
echo "at first glance,this doesn't appear to be a tarball."
fi
这个程序错在哪里?
我运行时来出现
./mytar.sh: line 3: syntax error near unexpected token `then'
./mytar.sh: line 3: `if["${1##*.}" = "tar"];then'
求高人指点一二。。。
|
if["${1##*.}" = "tar"];then
改为
if [ "${1##*.}" = "tar" ] ; then
改为
if [ "${1##*.}" = "tar" ] ; then
|
[]内各项必须用空格分开。也可以这样
[[ ${1##*.} == "tar" ]] && echo ... || echo ...
[[ ${1##*.} == "tar" ]] && echo ... || echo ...
|
记得[] 要有空格把"[" 和 "]" 分开