(copied directly from my other thread about something else)
At the moment, I just use...
cat config_file|grep var_name|cut -d'=' -f2
... which is fine for what I've been doing, but I'm not sure what to
do when there are a variable number of entries and I want it go through
them like a list.
Course, the config file itself could be a script but I prefer to keep
the configs seperate from the functions. Not really sure how to do
this. It's a problem sometimes, though I can usually hack up some kind
of work-around for my ignorance.
I don't think there's a general best way. Personally, I prefer the way you seem to dislike, which is just sourcing a "script" which does nothing but define variables.
The big exception to this is when there's multiple targets, for example a connectivity check script that should treat different targets in different ways. The config would be something like
and read it like this:
Course, the config file itself could be a script but I prefer to keep the configs seperate from the functions.
Don't put functions in your config files, then. :shrug: It's still the simplest and most direct way to do it, and the way its almost always done. You don't have to worry about comments or blank lines, the shell handles it.
Other alternatives usually involve eval which is, in the end, might as well just have sourced it since eval runs any shell statement, except that much harder for having to do all sorts of parsing yourself.
Last edited by Corona688; 09-22-2011 at 12:30 PM..
You don't need to use cat ... read useless use of cat (dont worry everyone has been there)
Interesting
So what do I use instead of cat for a line like this?
As to the question posting my config file, I don't have a specific one in mind. Something in another thread brought it to mind, and it's something I've been thinking about for a while.
------------------------------------------
As to the other comments:
Ok, I'll try doing it with scripts instead. The main config file I'm thinking provides variables for 17 different scripts (many of which both a) require the same variables and b) call eachother), so I'm not sure if it makes sense to have each of them loading all of the variables.,, I guess I could have any parent scripts load the proper variables into the sub-scripts... but some of them are called both independently and as a part of other operations. It's sort of complicated. since it's basically designed to shift my netbook between keyboard and tablet mode, and it manages all the settings for each mode, as well as things like rotating the screen and syncing the virtual keyboard with the screen orientation.
So far, I've just been "cat"ing all the required variables into each script as they are needed. I have no idea if this is the right way to do it. It's just what occured to me to do. That's sort of how all my scripting is. I just use the few commands I know to get the result I want. It usually works, but I'm sure there is all kinds of stupidity happening in the process(es?).
So what do I use instead of cat for a line like this?
Quote:
Originally Posted by ninjaaron
Ok, I'll try doing it with scripts instead. The main config file I'm thinking provides variables for 17 different scripts (many of which both a) require the same variables and b) call eachother), so I'm not sure if it makes sense to have each of them loading all of the variables.,,
Do it like it's usually done with headers in C: conditional includes
So no matter how often you source it, the variables are set only once.
Hi All,
Can anyone please explain me how to read data from config file in Perl.
Suppose i have a config file named cfile. The data in config file is
name=parth
lname=mittal
user=2007
hostname=fluoride
username=parthmittal
password=XXXXXX
account=unix
url=www.unix.com
... (2 Replies)
Hi,
I want to configure some values in config file like below
work_dir /home/work
csv_dir /home/csv
sql_dir /home/sqls
reportfirst yes
and i want to store each value in variable to use it further in my my perl program ??
any thought on this(i am new to perl) ?
... (2 Replies)
how to read the variable indivdually ( line by line ) in shell script
eg :
i have the config file where contain
cat /home/user01/ilap/conf/input.conf
node.txt
node2.txt
node3.txt
i need to run script like
/home/user01/ilap/exe/run.sh /home/user01/ilap/conf/input.conf
... (1 Reply)
Hi I am new to shell scripting. There is a requirement to write a shell script to meet follwing needs.Prompt reply shall be highly appreciated.
script that will compare two config files and produce 2 outputs - actual config file and a report indicating changes made.
OS :Susi linux ver 10.3.
... (4 Replies)
Hello everybody,
I'm coding a program in C and i'm getting troubles with this.
I need to read a config file and store the arguments into individual variables, let's say the config file looks like the following:
#This is the configuration file...
192.168.0.1 A1:B1:C1:D1:E1:F1
192.168.0.2... (2 Replies)
Hi,
I want to use a config file as the base file and parse over the values of country and city parameters in the config file and generate separate config files as explained below.
I will be using the config file as mentioned below:
(config.txt)
country:a,b
city:1,2
type:b1... (1 Reply)
Hello All,
I have a config file which has the following data :
export DBCHECKSUM001="/home/srvcdesk/DBCheckSum/DBCheckSum001.cfg"
export DBCHECKSUM002="/home/srvcdesk/DBCheckSum/DBCheckSum002.cfg"
export DBCHECKSUM003="/home/srvcdesk/DBCheckSum/DBCheckSum003.cfg"
export... (1 Reply)
how to read the variable from config file
eg: a.cfg below config file config file which contain
a=`hostname`
b=250
a.sh is shell script
echo "$a and $b"
if i run "a.sh 1.cfg" it works
but when i declare N number of variable it wont works..
can u please suggest for that ? (1 Reply)
Hello Friends
I am new to this forum and this is my first post.
I have to write a script in which i have to read data from a configuration ( .cfg) file. And also i have to execute/call some already written scripts from this script.
Can you people plpease help me on this regards.
Thanks... (5 Replies)