LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-26-2011, 03:12 AM   #1
GunnDawg
LQ Newbie
 
Registered: Jan 2011
Posts: 4

Rep: Reputation: 0
Question Shell Script Question.


I am trying to learn shell scripting and came up with a lil first script that I could actually use.

I have a basic shell script and all it does is run:
sudo apt-get update
sudo apt-get upgrade

So basically just a shell script that updates your packages. NOW, my question.

I made another shell script that makse a bit of a menu and asks what you wanna do, 1 to UPDATE or 2, to CLOSE.

How do I make it so when they enter 1 it runs my update.sh ?
 
Old 01-26-2011, 03:15 AM   #2
GunnDawg
LQ Newbie
 
Registered: Jan 2011
Posts: 4

Original Poster
Rep: Reputation: 0
It appears as though I got it. just had to append ./ in front of the filename.

How would I make it open up a NEW terminal and then run my .sh file in the new terminal?
 
Old 01-26-2011, 03:50 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,
Quote:
Originally Posted by GunnDawg View Post
It appears as though I got it. just had to append ./ in front of the filename.
That works if the file to be executed is in the same directory as the (menu) script.
More robust would be to use the full path to that script (I.e.: /home/user/bin/script.sh instead of ./script.sh)

Quote:
How would I make it open up a NEW terminal and then run my .sh file in the new terminal?
Assuming you are using an xterm: xterm scriptname.sh

This will open a new xterm, execute the script and closes the xterm once the script has stopped executing.

Hope this helps.
 
Old 01-26-2011, 04:07 AM   #4
GunnDawg
LQ Newbie
 
Registered: Jan 2011
Posts: 4

Original Poster
Rep: Reputation: 0
I am using Ubuntu 10.10 so I believe I am using GNOME and not xterm. I did however try your method like so..

case $opt in
1) xterm ./update.sh;;
2) nslookup;;
3) exit;;

and it seems as though an xterm terminal window did open up, but it didnt run the update.sh script (yes these are both in same directory). Also how would I go about making it launch update.sh in a gnome terminal and not xterm?

I tried:
1) gnome-terminal ./update.sh;;

It did open up a gnome terminal but did not launch update.sh.

Last edited by GunnDawg; 01-26-2011 at 04:09 AM.
 
Old 01-26-2011, 04:32 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Quote:
Originally Posted by GunnDawg View Post
I am using Ubuntu 10.10 so I believe I am using GNOME and not xterm. I did however try your method like so..

case $opt in
1) xterm ./update.sh;;
2) nslookup;;
3) exit;;

and it seems as though an xterm terminal window did open up, but it didnt run the update.sh script (yes these are both in same directory).
Doesn't the script run or does it close to fast to see (remember: after the script finishes, the terminal is immediately closed).

I'm not sure if xterm ./script.sh works, use the full path xterm /full/path/to/script.sh

Quote:
Also how would I go about making it launch update.sh in a gnome terminal and not xterm?

I tried:
1) gnome-terminal ./update.sh;;

It did open up a gnome terminal but did not launch update.sh.
I never use and do not have gnome-terminal installed, but a little on-line search tells me this:
gnome-terminal --working-directory=/full/path/to/script-dir -e ./script.sh

Hope this helps.
 
Old 01-26-2011, 04:37 AM   #6
GunnDawg
LQ Newbie
 
Registered: Jan 2011
Posts: 4

Original Poster
Rep: Reputation: 0
Actually it was pretty simple:

1) gnome-terminal -e ./update.sh;;

So I got it! Thank you for your input and help
 
Old 01-26-2011, 04:43 AM   #7
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
You're welcome
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script question psynce_friction Programming 10 11-21-2009 05:26 AM
Another shell script question J_Szucs Programming 4 09-10-2005 03:47 PM
Shell script question. pete1234 Programming 10 09-06-2005 03:46 AM
Shell Script Question swinchen Programming 1 08-20-2004 03:09 PM
shell script question Axion Programming 4 07-29-2004 10:51 PM


All times are GMT -5. The time now is 06:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration