reading configuration files in bash. Best way?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting reading configuration files in bash. Best way?
# 8  
Old 05-13-2010
Some of the locations have two words ...east this, or grand that, blah-blah
city. The tab is essential. This is one reason I was asking about the possibilities for sourcing the file with some variation of:

Code:
LOC1=( "Grand Rapids" 16 )
LOC2=( "East Shanghai" 11 )

To my thinking, though, it seems like it would require more processing in
the script rather than less, and so I opted for the solution posted. The
script would have to handle an unknown amount of variables in the sourced file and be able to process them not knowing much about them:
quantity, naming conventions ...etc. The file would be added to, possibly by someone not knowing how the script works. The simple while loop/IFS solution is both readable and reliable. The person adding to the file simply needs to remember to tab between fields.

Thanks again!

Bub
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compilation error when I run Bash configuration command

Hi, I downloaded source code file from The GNU website and changed the source code of ls.c file, added printf command to it. It worked fine. Then, I deleted the printf command, saved the file and ran the command 'make sudo && make install' closed the terminal and printf statement went away. I... (1 Reply)
Discussion started by: akanksha1509
1 Replies

2. Shell Programming and Scripting

Reading from file bash command

Hello, I have a file in the following format id sample platform R1 R2 gene1 gene2 gene3 1 abc llumina R1_001.fastq.gz R2_001.fastq.gz apoe prnpp asp 2 def llumina R1_001.fastq.gz R2_001.fastq.gz apoe prnpp 3 ghi llumina ... (3 Replies)
Discussion started by: nans
3 Replies

3. Shell Programming and Scripting

Reading a text file using bash

I've a file in linux with following text: ;ip address hostname put-location alt-put-location tftpserver 192.168.1.1 r01-lab1-net /mnt/nas1/fgbu/ /opt/fgbu/devicebackup 192.168.1.254Now I want to read these values and assign them to particular variables... (6 Replies)
Discussion started by: kashif.live
6 Replies

4. Programming

Reading a router configuration file

Hello C specialists, I'm trying to write a program to read out a binary configuration file produced by a router. But the output of Name and Value is cryptic. What's going wrong? The structure of the binary file is very simple: struct nvram_tuple { char *name; char *value; ... (5 Replies)
Discussion started by: digidax
5 Replies

5. UNIX for Dummies Questions & Answers

[bash] Reading two files and change a specific field

Hi all. I have 2 files like these: file1 3 -2 5 4 . . . 3 3 3 4 . . . 2 2 3 4 . . . 3 -2 8 4 . . . file2 0.4242 2 3 4 . . . 2.562 7 3 4 . . . 0.7242 5 5 4 . ... (3 Replies)
Discussion started by: t_studen_t
3 Replies

6. Shell Programming and Scripting

Help in reading a cv file in bash

Hi All, I am trying to read a .csv file which has some 6 columns. Eg: samp.csv one, two, three, four six, seven, eight, nine I used the following code, for line in `cat samp.csv` do echo "$line" done It displays every comma seperated values in each line like, one,... (1 Reply)
Discussion started by: johnwilliams.sp
1 Replies

7. Shell Programming and Scripting

Problem in reading file (bash)

i get a name from user first name : last name, in this format. Now i am saving this to a file. what i want is, I do not want to save any name if I already have one entry o that same name..what should i do for example user give robert fernandez this will save in file as robert:fernandez. if... (5 Replies)
Discussion started by: Learnerabc
5 Replies

8. Shell Programming and Scripting

bash reading and assigning

Hi, In a script i am having trouble joining a variable to a file. for, example I read input from user as a variable a or b or c or d etc and want to join those to different files... or if user press a then it will open somefile.txt if user press b then it will open otherfile.txt any idea (4 Replies)
Discussion started by: Learnerabc
4 Replies

9. Shell Programming and Scripting

Reading a value from the configuration file

Hi, I have prepared a config file in which I am declaring the value for a country such as: COUNTRY=USA Now I am trying to read the country from the config file and print a message based on the same. I have written the following code in a script and when executing the script I getting an error. ... (14 Replies)
Discussion started by: yoursdavinder
14 Replies

10. Shell Programming and Scripting

bash: reading filenames from file

Hi, I'm trying to write a script that reads filenames from a file and use these filenames in a loop. The filenames are all on one line and the problem is that these filenames have wildcards like * and braces like in them. Right now what I'm doing is something like this: echo "reading from... (0 Replies)
Discussion started by: warp17
0 Replies
Login or Register to Ask a Question
LIBBASH(7)							  libbash Manual							LIBBASH(7)

NAME
libbash -- A bash shared libraries package. DESCRIPTION
libbash is a package that enables bash dynamic-like shared libraries. Actually its a tool for managing bash scripts whose functions you may want to load and use in scripts of your own. It contains a 'dynamic loader' for the shared libraries ( ldbash(1)), a configuration tool (ldbashconfig(8)), and some libraries. Using ldbash(1) you are able to load loadable bash libraries, such as getopts(1) and hashstash(1). A bash shared library that can be loaded using ldbash(1) must answer 4 requirments: 1. It must be installed in $LIBBASH_PREFIX/lib/bash (default is /usr/lib/bash). 2. It must contain a line that begins with '#EXPORT='. That line will contain (after the '=') a list of functions that the library exports. I.e. all the function that will be usable after loading that library will be listed in that line. 3. It must contain a line that begins with '#REQUIRE='. That line will contain (after the '=') a list of bash libraries that are required for our library. I.e. every bash library that is in use in our bash library must be listed there. 4. The library must be listed (For more information, see ldbashconfig(8)). Basic guidelines for writing library of your own: 1. Be aware, that your library will be actually sourced. So, basically, it should contain (i.e define) only functions. 2. Try to declare all variables intended for internal use as local. 3. Global variables and functions that are intended for internal use (i.e are not defined in '#EXPORT=') should begin with: __<library_name>_ For example, internal function myfoosort of hashstash library should be named as __hashstash_myfoosort This helps to avoid conflicts in global name space when using libraries that come from different vendors. 4. See html manual for full version of this guide. AUTHORS
Hai Zaar <haizaar@haizaar.com> Gil Ran <ril@ran4.net> SEE ALSO
ldbash(1), ldbashconfig(8), getopts(1), hashstash(1) colors(1) messages(1) urlcoding(1) locks(1) Linux Epoch Linux