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
RBASH(1)						      General Commands Manual							  RBASH(1)

NAME
rbash - restricted bash, see bash(1) RESTRICTED SHELL
If bash is started with the name rbash, or the -r option is supplied at invocation, the shell becomes restricted. A restricted shell is used to set up an environment more controlled than the standard shell. It behaves identically to bash with the exception that the follow- ing are disallowed or not performed: o changing directories with cd o setting or unsetting the values of SHELL, PATH, ENV, or BASH_ENV o specifying command names containing / o specifying a file name containing a / as an argument to the . builtin command o specifying a filename containing a slash as an argument to the -p option to the hash builtin command o importing function definitions from the shell environment at startup o parsing the value of SHELLOPTS from the shell environment at startup o redirecting output using the >, >|, <>, >&, &>, and >> redirection operators o using the exec builtin command to replace the shell with another command o adding or deleting builtin commands with the -f and -d options to the enable builtin command o using the enable builtin command to enable disabled shell builtins o specifying the -p option to the command builtin command o turning off restricted mode with set +r or set +o restricted. These restrictions are enforced after any startup files are read. When a command that is found to be a shell script is executed, rbash turns off any restrictions in the shell spawned to execute the script. SEE ALSO
bash(1) GNU Bash-4.0 2004 Apr 20 RBASH(1)