Ubuntu在shell的執行上用戶root和普通用戶是不一樣的。使用vi /etc/passwd我們就可以看到在用戶的最後一行也就是定義shell執行位置的地方root的位置是/bin/bash 而其他的用戶都是/bin/sh
所以在Ubuntu中root執行scipt的時候應該是bash test.sh(注意在linux中是沒有文件後綴名的加上只是為了識別特殊的文件。文件能不能執行主要是看文件屬性裡面的x是否北打開)而不是sh test.sh。
#!/bin/bash
declare -i number2=10+100+1000
echo "Your result is $number1"
...:~$ sh test03-declare.sh
test03-declare.sh: 5: declare: not found
...:~$ bash test03-declare.sh
...:~$ Your result is 1110