LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 05-21-2009, 02:43 AM   #1
imprise
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?

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


Code:
linux-bhpq:~ # addpath
What directory do you want to add to the PATH?
/var/opt/mydb
Adding the /var/opt/mydb directory to the PATH...
linux-bhpq:~ # echo $PATH
/sbin:/usr/sbin:/usr/local/sbin:/opt/gnome/sbin:/root/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/games:/opt/gnome/bin:/opt/kde3/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin
linux-bhpq:~ #
Does my script has mistakes?

Thanks
 
Old 05-21-2009, 02:55 AM   #2
repo
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
Code:
export PATH
 
Old 05-21-2009, 03:04 AM   #3
imprise
LQ Newbie
 
Registered: May 2009
Distribution: SUSE
Posts: 20

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by repo View Post
Try to add
Code:
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, 03:08 AM   #4
rikijpn
Member
 
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 script.sh" try "source script.sh".

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


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


All times are GMT -5. The time now is 08:25 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