写了个脚本文件test.sh
#!/bin/bash
echo -e “Please input two number:”
read -p “first:” first
read -p “second:” second
declare -i total=$first*$second
echo -e “the result of $first x $second ==> $total”
执行该脚本文件bash test.sh,source test.sh都可以正常运行
但是sh test.sh,dash test.sh却不能正常运行,显示declare not found,这是怎么回事呢?请大家帮帮忙,帮我解答一下
#!/bin/bash
声明用bash来运行脚本的
如果用sh test.sh来执行,该怎么改写一下呢?
已经找到答案了!
用sh执行脚本*.sh文件,其中文件*.sh中包含declare的变量声明,但这样却现实not found declare,用chmod 755 .sh,然后./.sh脚本运行正常,或者直接bash *.sh也能运行,这是因为sh是链接的是dash,不是bash。
Ubuntu安装的时候使用了dash,dash比bash体积小速度快,兼容性高!但是在bash下可以正常运行的一些sh在dash下不能使用,造成了一些麻烦。为了解决之,键入sudo dpkg-reconfigure dash,重新配置dash,并选择“no”,即不使用dash。