shell - not found error when insert #!/bin/sh -
i started learning linux shell scripting, when writing script got error,
./my_script: 4: read: illegal option -n ./my_script: 5: ./my_script: [[: not found
i found out because #!/bin/sh line, can still run script without line won't execute codes such /n
#!/bin/sh # shell installer gurb customizer. 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 grub customizer\n" echo "gurb customizer" echo "a tool editing , configuring boot menu (grub2/burg).\n" read -p "do want install grub customizer $os ${ver} [$arch] ? (y/n) " -n 1 if [[ $reply =~ ^[yy]$ ]] echo "the installer downloading , installing grub customizer!"; echo "this action may require password.\n"; grabninstall else echo "user quit" echo "installation unsuccessful." fi
i'm doing on ubuntu 12.10.
and which sh gives output
/bin/sh
any idea did wrong?
the problem using /bin/sh
run script , on system /bin/sh -> dash
. means dash
executing script. dash
shell not support [[
, bash
does. should change first line in script (called shebang) #!/bin/sh
#!/bin/bash
.
alternatively, don't use [[
in script. use features support dash
.
also see this ubuntu page on constructs not supported in dash
.
Comments
Post a Comment