./*.sh 和 sh *.sh执行的结果不同
测试脚本文件windeal@ubuntu:~/Windeal/shell$ cat test.sh#!/bin/bash
echo "hello\n"
echo -e "hello\n"
windeal@ubuntu:~/Windeal/shell$
使用./*.sh执行结果为:windeal@ubuntu:~/Windeal/shell$ ./test.sh
hello\n
hello
windeal@ubuntu:~/Windeal/shell$
使用sh *.sh执行结果为windeal@ubuntu:~/Windeal/shell$ sh test.sh
hello
-e hello
windeal@ubuntu:~/Windeal/shell$另一个错误的例子
判断符 []在sh *.sh方式执行中不能成功
测试脚本如下windeal@ubuntu:~/Windeal/shell$ cat 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"
windeal@ubuntu:~/Windeal/shell$ 使用./*.sh方式执行没问题:windeal@ubuntu:~/Windeal/shell$ ./sh06.sh
Please enter (y/n):y
your input is y
windeal@ubuntu:~/Windeal/shell$
使用sh *.sh执行报错windeal@ubuntu:~/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
windeal@ubuntu:~/Windeal/shell$ 不明觉厉 ./*.sh 中echo应该 是调用的/bin/echo
sh *.sh中的echo应该是调用的shell内置的命令
嗯,应该是这样,你照这个方向查一下. q1208c 说sh != bash
页:
[1]