学习shell script,碰到如下问题:
#!/bin/bash
# Program:
# This program shows the user's choice
# History:
# 2005/08/25 VBird First release
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
read -p "Please input (Y/N): " yn
[ "$yn" == "Y" -o "$yn" == "y" ] && echo "OK, continue" && exit 0
[ "$yn" == "N" -o "$yn" == "n" ] && echo "Oh, interrupt!" && exit 0
echo "I don't know what your choice is" && exit 0
执行时总提示错误:
root@dustsnow-laptop:~/scripts# sh sh06.sh
Please input (Y/N): y
[: 10: y: unexpected operator
[: 11: y: unexpected operator
I don't know what your choice is
原因:
因为ubuntu默认的sh是连接到dash的,又因为dash跟bash的不兼容所以出错了.执行时可以把sh换成bash 文件名.sh来执行.成功.dash是什么东西,
by the way修改sh默认连接到bash的一种方法:
sudo dpkg-reconfigure dash
选择no即可.