LinuxQuestions.org
Register a domain and help support LQ
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-26-2011, 07:51 AM   #1
mtm100
LQ Newbie
 
Registered: Oct 2011
Posts: 6

Rep: Reputation: Disabled
Bash variables


Hi,

I'm very new to linux and am currently creating a very simple file backup script in bash and I am using Ubuntu.

I am calling backup.sh script from within the terminal using sudo bash backup.sh.

I have a configuration file separate from backup.sh (for ease of upgrade etc) , that contains variables e.g. email address to send logs to, location of log file, location of backup files etc. Both backup.sh and the config file will reside in the same folder.

How do I make the variables available to backup.sh easiest way possible as you guess by my question I'm a novice!

Thanks
 
Old 10-26-2011, 08:23 AM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650
It called sourcing .. you can just use a dot(.) followed by a space then followed by the path to the file.

Code:
#!/bin/bash

# import config
. /etc/myconfig.conf

...
 
Old 10-26-2011, 10:52 AM   #3
mtm100
LQ Newbie
 
Registered: Oct 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thanks kbp, saved me many tears, hours and swear words, thanks again.
 
Old 10-30-2011, 04:49 PM   #4
mtm100
LQ Newbie
 
Registered: Oct 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Similar question to the original, I have written a couple of functions that I am having to repeat across a couple of scripts (within the same back-up application) - is there a similar method for creating like a global (or sourcing file) where I can call them from?
Thanks
 
Old 10-30-2011, 04:53 PM   #5
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,811
Blog Entries: 1

Rep: Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191
Quote:
Originally Posted by mtm100 View Post
Similar question to the original, I have written a couple of functions that I am having to repeat across a couple of scripts (within the same back-up application) - is there a similar method for creating like a global (or sourcing file) where I can call them from?
Thanks
As far as I know, you could use exactly the same method, ie. sourcing:

Code:
. /path/to/file/with/global/functions
 
Old 10-31-2011, 11:27 AM   #6
mtm100
LQ Newbie
 
Registered: Oct 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Great, looks to be working by calling by:
. Configuration/myfunctions.sh
and then calling the function without containing the brackets e.g.
Logging_Events_Errors1

Thanks for your help
 
  


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
Variables and Mkvextract in a bash script and a good resource for bash help? gohmifune Linux - General 9 04-13-2011 09:37 AM
Bash Script: parse active process stderr, strip, dump into variables, use variables TimeFade Programming 1 02-13-2010 07:09 AM
Bash Variables SlipDigby Programming 2 09-01-2008 06:00 PM
variables in bash haddad Linux - General 6 09-22-2004 06:29 PM
Variables in bash tcaptain Programming 1 03-03-2003 03:07 PM


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