Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 05-21-2009, 03:43 AM   #1
LQ Newbie
Registered: May 2009
Distribution: SUSE
Posts: 20

Rep: Reputation: 0
Writing a simple script...

Hi all;

I wrote the following script on my SUSE Linux system, bur it does not apply?

#A script for adding a directory to the PATH environment veriable.
echo "What directory do you want to add to the PATH?"
echo "Adding the" $MYNEWPATH "directory to the PATH..."
exit 0
When I execute the above figure, the following happens:

linux-bhpq:~ # addpath
What directory do you want to add to the PATH?
Adding the /var/opt/mydb directory to the PATH...
linux-bhpq:~ # echo $PATH
linux-bhpq:~ #
Does my script has mistakes?

Old 05-21-2009, 03:55 AM   #2
LQ 5k Club
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,528

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Try to add
export PATH
Old 05-21-2009, 04:04 AM   #3
LQ Newbie
Registered: May 2009
Distribution: SUSE
Posts: 20

Original Poster
Rep: Reputation: 0
Originally Posted by repo View Post
Try to add
export PATH
Thanks for your reply. I added the "export PATH" command to the script, but the result is the same...
Old 05-21-2009, 04:08 AM   #4
Registered: Jun 2007
Location: Japan
Distribution: Debian lenny, DSL, Solaris 10
Posts: 157

Rep: Reputation: 33
You should know every shell has its own environment. When running a script, it has it's own environment, so if for example, you echo your PATH within your script (at the end of it, in your example), you'd get echoed your desired PATH(not gonna stay there though).
In order to get a variable "imported" into your current environment, from a script for example, you have to use the "source" command.
Instead of "bash" try "source".

Last edited by rikijpn; 05-21-2009 at 04:10 AM.


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
Need help writing a simple bash script linuxmaveric Programming 3 12-06-2007 07:53 PM
Need help in writing simple shell script to format names naren_0101bits Programming 3 08-14-2007 11:59 AM
Writing a simple auto-reconect script for KInternet in SUSE 9.3 tomazN Linux - Networking 0 07-11-2005 11:21 AM
Help writing a simple script Garibaldi3489 Linux - General 10 12-18-2004 07:22 PM
Simple script writing help - digital camera EuroJovi Linux - General 2 02-01-2004 05:01 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:24 AM.

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