————《鸟哥的Linux私房菜——基础篇》学习笔记
ubuntu默认的sh是连接到dash,而我们写shell脚本时使用的时bash。bash和dash在一些方面是不兼容的。因此执行同一个脚本,两者结果不一样,可能用./*sh可以执行,而sh *.sh报错。
为了正确实行使用./*.h 或者 bash *.sh 或者把==换成=(不兼容部分)
也可以直接让系统不使用dash。。。。Ubuntu之所以使用dash是因为其体积小,兼容性高,但是悲催的时,一些bash可执行的脚步在dash下不能执行了。
鸟哥私房菜13章学习shell script 中2.2节有一个例子sh06.sh
#!/bin/bash #Program # "test the func of []" #History: #2014-08-14 Windeal #version 1 #All rights reserved; PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH read -p "Please enter (y/n):" yn [ "$yn" == "Y" -o "$yn" == "y" ] && echo "your input is y" && exit 0 [ "$yn" == "N" -o "$yn" == "n" ] && echo "your input is n" && exit 0 echo "I don't know what you choice\n" ~
使用sh执行报错:
[email protected]:~/Windeal/shell$ sh sh06.sh Please enter (y/n):y sh06.sh: 12: [: y: unexpected operator sh06.sh: 13: [: y: unexpected operator I don't know what you choice [email protected]:~/Windeal/shell$
使用./sh06.sh 可以执行
[email protected]:~/Windeal/shell$ ./sh06.sh Please enter (y/n):y your input is y [email protected]:~/Windeal/shell$
Ubuntu下sh *.sh使用==操作符执行报错
时间: 2024-10-13 09:05:25