我开始学习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知道我哪里做错了吗?
发布于 2013-05-13 08:01:24
问题在于您正在使用/bin/sh来运行脚本,并在您的系统/bin/sh -> dash上运行。这意味着dash正在执行您的脚本。dash shell不支持[[,但bash支持。因此,您应该将脚本中的第一行(称为谢邦)从#!/bin/sh更改为#!/bin/bash。
或者,不要在脚本中使用[[。只使用dash支持的特性。
还请参阅这个Ubuntu页面中哪些构造在dash中不受支持。
https://stackoverflow.com/questions/16517078
复制相似问题