我开始学习 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 上这样做。
哪个 sh给出了这个输出
/bin/sh
知道我在哪里做错了吗?