When I run a bash script from terminal or nautilus, it works properly, but when I run it via gnome's 'Main Menu', it returns an error.
read -p "" -n1 selection
This is the line, that return the following error:
/usr/local/bin/php-version.sh: 9: read: Illegal option -n
But when I run the script via terminal (./file.sh
), there's no problem with this
The Main Menu entry is bash usr/local/bin/php-version.sh
File permissions are 755, owner is root.
EDIT:
/usr/local/bin/php-version.sh
#!/bin/bash
sudo echo -e "sudo/root permission: \e[32mOkay\e[0m"
echo -e "Type \e[2m5\e[0m to change from php version \e[1m7 \e[0mto \e[1m5\e[0m"
echo -e "Type \e[2m7\e[0m to change from php version \e[1m5 \e[0mto \e[1m7\e[0m"
echo -en "\e[1mSelect: \e[0m"
read -p "" -n1 selection
echo
case "$selection" in
"5")
sudo a2dismod php7.0 >> /dev/null
sudo a2enmod php5 >> /dev/null
sudo a2query -m php5
;;
"7")
sudo a2dismod php5 >> /dev/null
sudo a2enmod php7.0 >> /dev/null
sudo a2query -m php7.0
;;
*)
sudo echo -e "\e[91mInvalid input: \e[39m$selection\e[0m"
echo -en "\e[2mPress Enter..."; sed -n q </dev/tty
exit 1
;;
esac
echo "Restarting apache2..."; sudo service apache2 restart
echo -en "\e[2mPress Enter..."; sed -n q </dev/tty
/usr/local/bin/test.sh (where the read
command always works)
#!/bin/bash
ps aux | grep $$ | grep -v grep
read -p "" -n1 test
echo -e "\n"
env
$SHELL
test.sh
to check whether gnome does really start a non-posix bash whereread -n
should work? test.sh could doenv
to see all variables andps aux | grep $$ | grep -v grep
to see which shell is used.ps aux | grep $$ | grep -v grep
returnsscriptim 3669 0.0 0.0 13236 2844 pts/1 Ss+ 00:08 0:00 /bin/bash /usr/local/bin/test.sh
(terminal)scriptim 5188 0.0 0.0 13236 2852 pts/1 Ss+ 00:15 0:00 bash /usr/local/bin/test.sh
(Main Menu) POSIXLY_CORRECT is not definedphp-version.sh
. Could you post both the workingtest.sh
and the badphp-version.sh
? (Edit your question.)