LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 10-16-2006, 09:27 AM   #1
basher400
Member
 
Registered: Mar 2005
Posts: 54

Rep: Reputation: 15
Question setting variables in an exteral file


hi

I made 3 .sh files("page1.sh", "page2.sh and "page3.sh") that all use this 2 certain paths:
Code:
book_path="/usr1/argo/home/fim/1.htm"
home_path="/usr1/argo/home/fim/home.htm"
now instead of using the above line in every of the 3 files, I want to use a "setting" file, lets say "setting.sh" that will contain these 2 vars so I can only include the "setting.sh" file in each of the 3 .sh files and will have only one place to edit those vars in case I need to.

how do I do that ?
I tried to use the following line at the top of eash of the files:
Code:
./settings.sh
(which is the correct path to the "setting.sh" file) but it didn't work.
 
Old 10-16-2006, 09:45 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Hi,

You can source the file from within the script. I.e:
Code:
$ cat settings.sh 
book_path="/usr1/argo/home/fim/1.htm"

 $ cat page1.sh
#!/bin/bash

. settings.sh
 
echo $book_path
Whe you run page1.sh all vars in settings.sh will be available inside the script:
Code:
$ ./page1.sh
/usr1/argo/home/fim/1.htm
Hope this helps.
 
Old 10-16-2006, 10:07 AM   #3
olaola
Member
 
Registered: Aug 2006
Location: Italy
Distribution: Fedora
Posts: 41

Rep: Reputation: 15
solution provide by druuna is correct

your original method does not work because every bash script you run, start in a different instance of bash and the value of setted variables vanish at the end of the script.
 
Old 10-18-2006, 03:46 AM   #4
basher400
Member
 
Registered: Mar 2005
Posts: 54

Original Poster
Rep: Reputation: 15
thanks
god bless
 
  


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
setting env. variables arunsri Slackware 3 03-26-2005 05:49 AM
Setting Bash Variables from outside data file llewis Programming 10 01-12-2005 04:30 AM
Exteral USB hard drive with multiple partitions moxx Linux - Hardware 5 05-02-2004 02:50 PM
setting enviroment variables unimaginative Linux - General 5 01-08-2004 01:22 AM
setting environment variables rezza Linux - Distributions 2 04-09-2003 08:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:29 AM.

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