I have been having an extremely annoying problem. For the record, I am relatively new at this. I've only been working with unix-based OS's for roughly two years, mostly Xubuntu and some Kali. I am pretty familiar with the BASH language, as that's the default shell for debian. Now, I've made this BASH script that works properly when it is accessed through the virtual console, xfce4-terminal 0.6.3. I've created a symbolic link in /bin to access the script from any directory, as most people do, I think. This is the script itself, designed to connect to WiFi access point from a CLI or virtual terminal.
#!/bin/bash
# WiFi Commander, a lazy way to lazily connect to the WiFi
# Updated: 2-2-16, version 1.6
# This script requires that nmcli, w3m, and w3m-img (if
# you want to be able to see pictures), are all installed
# on the computer running it
DDG="www.duckduckgo.com"
Cmdr () {
echo; echo "WiFi Command??"; echo
read command
}
test () {
echo; ping -c 1 $DDG
if [ "$?" -eq "0" ];
then echo; echo "Connection Successful."
else echo; echo "Connection Unsuccessful."
fi
}
interweb () {
echo; w3m $DDG
if [ "$?" -eq "0" ];
then echo " ";
else echo; echo "You are not connected to the internet."
fi
}
menu () {
echo; echo "Command Menu:"; echo
echo "S: Scan for WiFi"
echo "CTN: Connect to new WiFi"
echo "C: Connect to a Saved Connection"
echo "T: Test Connection"
echo "D: Disconnect from WiFi"
echo "VC: View Saved Connections"
echo "DelCon: Delete a Saved Connection"
echo "LB: Launch Browser (W3M)"
echo "SM: Show this Menu"
echo "E: Exit"
}
echo; echo "Welcome to WiFi Commander."; sleep .75
menu
while true; do
Cmdr
if [[ "$command" == S ]] || [[ "$command" == s ]];
then echo; echo $(iwlist scan | grep -E "Quality|Signal level|Encryption key|ESSID"; echo);
elif [[ "$command" == CTN ]] || [[ "$command" == ctn ]];
then echo; echo "SSID:"; echo; read ssid; echo; echo "Key:"; echo; read passwd; sudo nmcli d wifi connect "$ssid" password "$passwd" iface wlan0; echo
elif [[ "$command" == C ]] || [[ "$command" == c ]];
then echo; echo $(nmcli c); echo; echo "Connect to??"; echo; read ssid; nmcli c up id "$ssid";
elif [[ "$command" == T ]] || [[ "$command" == t ]];
then test
elif [[ "$command" == D ]] || [[ "$command" == d ]];
then nmcli d disconnect wlan0
elif [[ "$command" == VC ]] || [[ "$command" == vc ]];
then echo; echo $(nmcli c); echo
elif [[ "$command" == DelCon ]] || [[ "$command" == delcon ]];
then echo; echo $(nmcli c); echo; echo "Delete which??"; echo; read ssid; nmcli c delete id "$ssid";
elif [[ "$command" == LB ]] || [[ "$command" == lb ]];
then interweb
elif [[ "$command" == SM ]] || [[ "$command" == sm ]];
then menu
elif [[ "$command" == E ]] || [[ "$command" == e ]];
then echo; echo "Goodbye."; echo; exit
else echo; echo "Error: Command not recognised."
fi
done
This application when summoned via the symbolic link I've created for it, "w-cmdr", runs perfectly. But when I create a graphical launcher, the same kind that functions, say, an Internet browser, or a common application such as LibreOffice, it will not function. It executes the first actual command, which introduces the script and awaits the "command" from the script's "command menu" (as shown in the first picture). But anything actually entered into that menu results in a script failure, from which the only way to exit the script is CTRL+C. The failure is shown in the second picture.
What I don't understand is why it runs when originally executed by the CLI or virtual console, but when summoned by a graphical application launcher, which is configured to bring up a virtual console via the "run in terminal" option, as shown in the third picture, fails with no explanation. I use this script often, even when I'm using the GUI, and having a graphical launcher is honestly, not terribly important. But in enhances my laziness, which is the point of shell scripts haha. So please, someone help me. This is very frustrating. Any suggestions or ideas would be appreciated.