刚开始学习shell的条件判断if [] ;then 时,vi 输入这么一个小程序:
#!/bin/bash
echo "please y to continue"
read yn
if [ "$yn"="y" ]; then
echo "script is runing"
else
echo "stop"
fi
然后执行,就出现了这么一个错误:
test1.sh: line 4: syntax error near unexpected token `then'
test1.sh: line 4: `if[ "$yn"="y" ]; then'
一直找了挺久,才知道if 和[ ]之间要加空格。。。
好吧,感觉shell很多时候空格是个很重要的东西,一不小心如果没有空格,错误就找上你了
所以,好习惯就是:不要省空格