Cannot get terminal application to launch with a graphical launcher when successful in terminal


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cannot get terminal application to launch with a graphical launcher when successful in terminal
# 8  
Old 02-15-2016
There is a space before the shebang on the first line. The OS I'm using is Kali (the new Rolling version) which I believe by default uses Bourne again shell as the interpreter. Also, the way that I wrote the shebang with the space leading has always been how I've always written it. I didn't know that it made a difference for there to be a space?? But I'm new at this, also. And thank you for clarifying about the test statements, that was very helpful. So should the shebang not have a space in front of it?? If I were to use this script on a different OS that doesn't use bash, and that space were there before the shebang, would that different OS not know what interpreter to use?? Again, thank you for your time.

---------- Post updated at 04:48 PM ---------- Previous update was at 04:44 PM ----------

@ RudiC

I've been trying to implement the "select" statement in my script but it hasn't been very successful, as it is a very unfamiliar concept to me. But thank you for your time and idea, I'm sure if I fiddle around with it long enough, I'll get the hang of it haha.
# 9  
Old 02-15-2016
Quote:
Originally Posted by Huitzilopochtli
There is a space before the shebang on the first line. The OS I'm using is Kali (the new Rolling version) which I believe by default uses Bourne again shell as the interpreter. Also, the way that I wrote the shebang with the space leading has always been how I've always written it. I didn't know that it made a difference for there to be a space?? But I'm new at this, also. And thank you for clarifying about the test statements, that was very helpful. So should the shebang not have a space in front of it?? If I were to use this script on a different OS that doesn't use bash, and that space were there before the shebang, would that different OS not know what interpreter to use?? Again, thank you for your time.
I repeat: " Unless #!interpreter_path starts in column 1 on the 1st line in your file, that line is just a comment and has absolutely no effect on what interpreter will be used to run your script." A leading space makes a HUGE difference. Any attempt on any UNIX-like operating system to exec a shell script that does not have #! as the 1st two characters in that file will be run by that system's default shell.

If the #!/interpreter/path start in the 1st character of the 1st line of your file and the operating system doesn't find an executable file with that path, you're likely to get a cryptic message like:
Code:
-bash: script_file not found

(assuming that your login shell is bash and the name of the shell script you were trying to execute was named script_file).

With the space there, another operating system (or your own) will know exactly what shell to use to invoke your script (that system's default) which will probably be named sh and might or might not be linked to bash, ksh, dash, ..., or a 1970's vintage pure Bourne shell depending on what operating system you are using at the time.

Of course, you can always use:
Code:
bash script_file

to have bash run script_file no matter what the first line of script_file looks like.
This User Gave Thanks to Don Cragun For This Post:
# 10  
Old 02-15-2016
@ RudiC

I tried to use the "select" statement for my script and couldn't figure out how to implement it correctly. But thank you for your time, I'm sure that if I keep messing around with it, I'll figure it out eventually haha.

---------- Post updated at 07:18 PM ---------- Previous update was at 07:12 PM ----------

@ Don Cragun

Thank you for clarifying the difference between the two "test" statements, it's really helped a lot. Also, I am aware of where my shebang is, and I have always had it like that in every script that I've ever written. The OS that I'm using is the Kali Rolling version, and I do believe that it's default interpreter is the Bourne again shell. I'm curious, does the space before the shebang really make a difference?? If I were to try and use this script in a different OS that does not use BASH as its default interpreter, would the script fail?? Does the space before the shebang, in that way, nullify the presence of that shebang??

Again, thank you for your time.
# 11  
Old 02-15-2016
Quote:
Originally Posted by Huitzilopochtli
@ RudiC

I tried to use the "select" statement for my script and couldn't figure out how to implement it correctly. But thank you for your time, I'm sure that if I keep messing around with it, I'll figure it out eventually haha.

---------- Post updated at 07:18 PM ---------- Previous update was at 07:12 PM ----------

@ Don Cragun

Thank you for clarifying the difference between the two "test" statements, it's really helped a lot. Also, I am aware of where my shebang is, and I have always had it like that in every script that I've ever written. The OS that I'm using is the Kali Rolling version, and I do believe that it's default interpreter is the Bourne again shell. I'm curious, does the space before the shebang really make a difference?? If I were to try and use this script in a different OS that does not use BASH as its default interpreter, would the script fail?? Does the space before the shebang, in that way, nullify the presence of that shebang??

Again, thank you for your time.
Please review post #9 in this thread!
# 12  
Old 02-15-2016
Thank you for that clarification about the shebang. And also, please ignore the repeated replies over the same thing, I'm new to this website and am not very familiar with its nuances. I thought that the first time that I replied, it didn't go through.

Thank you for your time, you've really helped me a lot to have a better understanding of the BASH language and scripting in general.

Last edited by Huitzilopochtli; 02-15-2016 at 07:32 PM..
# 13  
Old 02-16-2016
select will take ANY list and turn it into a menu:
Code:
PS3="Enter Value X: "
select X in A B C D E F; do echo $X; done
1) A
2) B
3) C
4) D
5) E
6) F
Enter Value X:

Then, add a case ... esac construct ...
These 2 Users Gave Thanks to RudiC For This Post:
# 14  
Old 02-16-2016
@ RudiC

Well, I've half successfully implemented the "select" statement in my script, but instead of actually doing the command, it just tells me the command linked to the number. The "case" statement functions fine in the version of this script before I added the "select" part.

Here is the script now:
Code:
#!/bin/bash

 # WiFi Commander, a lazy way to lazily connect to the WiFi

 # Unstable

 # 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"

test () {
echo; ping -c 1 $DDG
if [ "$?" -eq "0" ];
then echo; echo "Connection Successful."
else echo; echo "Connection Unsuccessful."
fi
}

discon () {
nmcli d disconnect wlan0
if [ "$?" -eq "10" ];
then echo; echo "wlan0 not found: Testing for wlan0mon...."; echo; sleep .75; discon2
fi
}

discon2 () {
nmcli d disconnect wlan0mon
if [ "$?" -eq "10" ];
then echo; echo "Error with the WiFi Adapter."
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; echo

PS3="WiFi Command: "
select command in "Scan for WiFi" "Connect to new WiFi" "Connect to a Saved Connection" "Test Connection" "Disconnect from WiFi" "View Saved Connections" "Delete a Saved Connection" "Launch Browser (W3M)" "Show this Menu" "Exit"; do echo $command; done
1) "Scan for WiFi"
2) "Connect to New WiFi"
3) "Connect to a Saved Connection"
4) "Test Connection"
5) "Disconnect from WiFi"
6) "View Saved Connection"
7) "Delete a Saved Connection"
8) "Launch Browser (W3M)"
9) "Show this Menu"
10) "Exit"
WiFi Command: 

case $command in

([1]) echo; echo $(iwlist scan | grep -E "Quality|Signal level|Encryption key|ESSID"); echo;;
([2]) echo; echo "SSID:"; echo; read ssid; echo; echo "Key:"; echo; read passwd; sudo nmcli d wifi connect "$ssid" password "$passwd"; echo;;
([3]) echo $(nmcli c); echo; echo "Connect to??"; echo; read ssid; nmcli c up id "$ssid";;
([4]) test;;
([5]) discon;;
([6]) echo; echo $(nmcli c); echo;;
([7]) echo; echo $(nmcli c); echo; echo "Delete which??"; echo; read ssid; nmcli c delete id "$ssid";;
([8]) interweb;;
([9]) menu;;
([10]) echo; echo "Goodbye."; echo; exit;;
*) echo; echo "Error: Command not recognised.";;

esac

The picture is of what happens when an option is entered into the script. As you can see, the command associated with the number from the "select" statement is not actually executed.

I'm not quite sure what is wrong with this, as the "select" statement is very new to me.

Once again, I thank you for your time.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print Terminal Output Exactly how it Appears in the Terminal to a New Text File

Hello All, I have a text file containing output from a command that contains lots of escape/control characters that when viewed using vi or view, looks like jibberish. But when viewed using the cat command the output is formatted properly. Is there any way to take the output from the cat... (7 Replies)
Discussion started by: mrm5102
7 Replies

2. UNIX for Dummies Questions & Answers

Routing command to another graphical terminal

So, I'm in a graphical terminal (xfce4-terminal) and I was wondering, would there be a way to type a command, and it run in a new terminal window?? An example would be like, say that I want to open a .txt file, but I want it in a different window, instead of the one that I'm currently using because... (1 Reply)
Discussion started by: Huitzilopochtli
1 Replies

3. UNIX for Dummies Questions & Answers

pbpaste to application in terminal

Is it possible to execute a pbpaste command to an application or current application in focus? Thanks (0 Replies)
Discussion started by: fhill2
0 Replies

4. Red Hat

Not able to see the terminal icon in the applications menu to launch the command prompt in Centos

After installing centos iam not able to see the terminal icon in the applications menu to launch the command prompt in Centos. However iam able to see the Open Terminal menu, when i right click and it is not working. let me know what are the things i need to check.:b: (1 Reply)
Discussion started by: Kesavan
1 Replies

5. OS X (Apple)

Can't launch x11 remotely from terminal

After I installed OS X Lion I haven't been able to launch x11 remotely (using ssh) from Terminal. It works fine locally, and also remotely directly from the Xterm. I log in to the unix server at my university from the terminal like this: ssh -l -X login@host.com This used to launch... (1 Reply)
Discussion started by: gnyrf
1 Replies

6. Shell Programming and Scripting

How do I launch a command on an existing terminal in unix using PERL

Hello, I have a PERL-TK based GUI from which I want to launch a command on an existing UNIX terminal (this is also the parent terminal for this perl based gui window). The command I want to launch is interactive (there is no intention to interact with that command from the same PERL gui i.e. no... (2 Replies)
Discussion started by: AnuragJindal
2 Replies

7. Programming

Redirecting Terminal to Local Application!

i wanted to execute some terminal commands on local linux, parse their output and display it to the user, i checked netcat source code but i couldnt understance it since im new to c (and linux at the same time). so i was wondering if there is away to run an instance of terminal hidden, read and... (15 Replies)
Discussion started by: JonhyM
15 Replies

8. OS X (Apple)

Need help writing an Applescript to launch a specific Terminal Command...

I developed a script in Lingon (which is an automated script editor developed for OS X) that is used to automatically restart programs only if they crash. The script itself does just that, but I only want it to load if I'm going to use the specific application that it's designed to protect. In the... (2 Replies)
Discussion started by: JFraser1
2 Replies

9. Shell Programming and Scripting

Need help writing an Applescript to launch a specific Terminal Command...

I developed a script in Lingon (which is an automated script editor developed for OS X) that is used to automatically restart programs only if they crash. The script itself does just that, but I only want it to load if I'm going to use the specific application that it's designed to protect. In... (3 Replies)
Discussion started by: JFraser1
3 Replies

10. Solaris

Script to launch terminal window?

Hi, I am a newbie here. Trying to find a way of writing a script to launch multiple terminal or console windows on solaris 9. I used to be able to do this using cmdtool on older versions of solaris and it was even possible to configure the size and screen position of the window and the title. ... (5 Replies)
Discussion started by: omerta
5 Replies
Login or Register to Ask a Question