我开始学习Linux shell脚本编程。当我编写这个脚本时,出现了错误。
./my_script: 4: read: Illegal option -n
./my_script: 5: ./my_script: [[: not found
我发现问题出在#!/bin/sh这一行,如果我不加这一行也可以运行脚本,但是像/n这样的代码就不会被执行。
#!/bin/sh
# Shell installer for gurb customizer. by Naveen Gamage.
OS=$(lsb_release -si)
ARCH=$(uname -m | sed 's/x86_//;s/i[3-6]86/32/')
VER=$(lsb_release -sr)
grabninstall() {
sudo add-apt-repository ppa:danielrichter2007/grub-customizer
sudo apt-get update
sudo apt-get install grub-customizer
}
echo "Installer for GRUB CUSTOMIZER\n"
echo "GURB CUSTOMIZER"
echo "A tool for editing and configuring boot menu (GRUB2/BURG).\n"
read -p "Do you want to install Grub Customizer for $OS ${VER} [$ARCH] ? (Y/n) " -n 1
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "The installer is downloading and installing GRUB Customizer!";
echo "This action may require your password.\n";
grabninstall
else
echo "user quit"
echo "Installation was unsuccessful."
fi
我正在使用Ubuntu 12.10。
which sh的输出结果为:
/bin/sh
我做错了什么?
ls -l /bin/sh
是否指向bash
? - dogbane