Sponsored Content
Top Forums Shell Programming and Scripting Cannot get terminal application to launch with a graphical launcher when successful in terminal Post 302966907 by Huitzilopochtli on Wednesday 17th of February 2016 07:11:30 PM
Old 02-17-2016
@ RudiC

Thank you for that clarification. Although it took me a good while to mess around with it, I finally figured out what I had wrong. Truly, a novice mistake haha. But I understand the "select" statement now, and it has helped improve the script, and will help me improve other scripts that I write. Again, thank you for your time and knowledge, they have both proved to invaluable.


For those who care, the new script, which is fully operational, is as follows below.

Code:
#!/bin/bash

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

 # Updated: 17-2-16, Version 2.3

 # 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

 # You must be a sudoer or root to use this script

DDG="www.duckduckgo.com"

wa () {
sudo ifconfig | grep -Eow "wlan0"; sudo ifconfig wlan0 up
if [ "$?" -eq "0" ];
then echo; echo "wlan0 is present."; sudo ifconfig wlan0 up
else echo; echo "wlan0 is not present. Testing for wlan0mon...."; echo; sleep .75; wa2
fi
}

wa2 () {
sudo ifconfig | grep -Eow "wlan0mon"; sudo ifconfig wlan0mon up
if [ "$?" -eq "0" ];
then echo; echo "wlan0mon is present."; sudo ifconfig wlan0mon up
else echo; echo "No wireless devices are present."
fi
}

scan () {
echo; echo $(sudo iwlist scanning | grep -E "Quality|Signal level|Encryption key|ESSID"); echo
if [ "$?" -ne "0" ];
then echo; echo $(sudo iwlist scanning | grep -E "Quality|Signal level|Encryption key|ESSID"); echo
fi
}

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
}


echo; echo "Welcome to WiFi Commander."; sleep .75; echo

PS3="WiFi Command: "
echo "Command Menu:"; echo; select command in "Activate Wireless device" "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)" "Exit"
do
case $command in
"Activate Wireless device") wa;;
"Scan for WiFi") scan;;
"Connect to new WiFi") echo; echo "SSID:"; echo; read ssid; echo; echo "Key:"; echo; read passwd; sudo nmcli d wifi connect "$ssid" password "$passwd"; echo;;
"Connect to a Saved Connection") echo $(nmcli c); echo; echo "Connect to??"; echo; read ssid; nmcli c up id "$ssid";;
"Test Connection") test;;
"Disconnect from WiFi") discon;;
"View Saved Connections") echo; echo $(nmcli c); echo;;
"Delete a Saved Connection") echo; echo $(nmcli c); echo; echo "Delete which??"; echo; read ssid; nmcli c delete id "$ssid";;
"Launch Browser (W3M)") interweb;;
"Exit") echo; echo "Goodbye."; echo; exit;;
*) echo; echo "Command not recognised.";;
esac
echo; echo "Press Enter to view the Command Menu again."; echo
done

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
ECHO(3) 								 1								   ECHO(3)

echo - Output one or more strings

SYNOPSIS
void echo (string $arg1, [string $...]) DESCRIPTION
Outputs all parameters. echo is not actually a function (it is a language construct), so you are not required to use parentheses with it. echo (unlike some other language constructs) does not behave like a function, so it cannot always be used in the context of a function. Additionally, if you want to pass more than one parameter to echo, the parameters must not be enclosed within parentheses. echo also has a shortcut syntax, where you can immediately follow the opening tag with an equals sign. Prior to PHP 5.4.0, this short syn- tax only works with the short_open_tag configuration setting enabled. I have <?=$foo?> foo. PARAMETERS
o $arg1 - The parameter to output. o $... - RETURN VALUES
No value is returned. EXAMPLES
Example #1 echo examples <?php echo "Hello World"; echo "This spans multiple lines. The newlines will be output as well"; echo "This spans multiple lines. The newlines will be output as well."; echo "Escaping characters is done "Like this"."; // You can use variables inside of an echo statement $foo = "foobar"; $bar = "barbaz"; echo "foo is $foo"; // foo is foobar // You can also use arrays $baz = array("value" => "foo"); echo "this is {$baz['value']} !"; // this is foo ! // Using single quotes will print the variable name, not the value echo 'foo is $foo'; // foo is $foo // If you are not using any other characters, you can just echo variables echo $foo; // foobar echo $foo,$bar; // foobarbarbaz // Some people prefer passing multiple parameters to echo over concatenation. echo 'This ', 'string ', 'was ', 'made ', 'with multiple parameters.', chr(10); echo 'This ' . 'string ' . 'was ' . 'made ' . 'with concatenation.' . " "; echo <<<END This uses the "here document" syntax to output multiple lines with $variable interpolation. Note that the here document terminator must appear on a line with just a semicolon. no extra whitespace! END; // Because echo does not behave like a function, the following code is invalid. ($some_var) ? echo 'true' : echo 'false'; // However, the following examples will work: ($some_var) ? print 'true' : print 'false'; // print is also a construct, but // it behaves like a function, so // it may be used in this context. echo $some_var ? 'true': 'false'; // changing the statement around ?> NOTES
Note Because this is a language construct and not a function, it cannot be called using variable functions. SEE ALSO
print(3), printf(3), flush(3), Heredoc syntax. PHP Documentation Group ECHO(3)
All times are GMT -4. The time now is 12:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy