Ubuntu 下使用declare的问题


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

相关内容