Read values from file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read values from file.
# 8  
Old 04-21-2012
VAR="${VAR// }" does not work in /bin/sh on Ubuntu, neither do arrays nor indirect references. You need to make sure the script is run with bash.
# 9  
Old 04-22-2012
Quote:
Originally Posted by kashif.live
what is way to fix this issue? and is there any way that i can keep same code for both servers? thanks in advance.
As Scrutinizer says use bash if you want arrays, etc. Put #!/bin/bash on the first line assuming you have bash installed on CentOS.

But let's get back to the array, With the code you are curently using anything before the "=" in the configfile is irrelevent: line 1 will go into array element #1 line 2 in #2, etc. Having said that you could simpify things by having your config file with just the values:
configfile:
Code:
Alpha Tech
test@hotmail.com
Password
abc@live.com
smtp.live.com:587

script:
Code:
#!/bin/bash
IFS=$'\n' Values=( "" $(< configfile) )
echo "Company=${Values[1]}"

Or keep support for named params and source the configfile eg:
configfile:
Code:
Company="Alpha Tech"
FromEmail="test@hotmail.com"
Password="Password"
ToEmail="abc@live.com"
Smtp="smtp.live.com:587"

script:
Code:
#!/bin/bash
. configfile
Values=( "" "$Company" "$FromEmail" "$Password" "$ToEmail" "$Smtp" )
echo "Company=${Values[1]}"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read a file and replace values in a script

Hi , I have a property file placed in folder /usr/opt/temp/aorc.prop which has values given below . I need to read this file content and replace the node with actual values in a shell script . Each time the script shall replace the node value from the poperty file and execute a cfsend command and... (10 Replies)
Discussion started by: samrat dutta
10 Replies

2. Shell Programming and Scripting

awk file to read values from Db2 table replacing hard coded values

Hi, I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below... if (start_new_rec=="true"){ exclude_user="false"; user=toupper($6); match(user, "XXXXX."); if (RSTART ==2 ) { ... (9 Replies)
Discussion started by: asandy1234
9 Replies

3. Shell Programming and Scripting

Read values from second file in awk

Hello Friends, I have written a script like the following, which finds some logs and fetchs some desired rows and then calculate average processing time of a spesific application. if then echo echo "----- There are three arguments which is expected to run this script! ... (5 Replies)
Discussion started by: EAGL€
5 Replies

4. Shell Programming and Scripting

Read record from the text file contain multiple separated values & assign those values to variables

I have a file containing multiple values, some of them are pipe separated which are to be read as separate values and some of them are single value all are these need to store in variables. I need to read this file which is an input to my script Config.txt file name, first path, second... (7 Replies)
Discussion started by: ketanraut
7 Replies

5. Shell Programming and Scripting

How to Read different values from external file?

Hi , I am new to this scripting , I am facing an issue like how to read different values from external file by using different variables, In script I supposed to declare var 1 var 2 var 3 I know how to call this variables from external file (I am using awk command by giving same... (3 Replies)
Discussion started by: chandini
3 Replies

6. Shell Programming and Scripting

Read variables and their values from file

Hi, I want to read the variables and the values from the txt file and compare these values with the ones computed by script. for ex: say var.txt contains the variable names and their values: one 1 two 2 three 3 The value of variables "one" "two" and "three" will be computed in the script... (3 Replies)
Discussion started by: bhushana
3 Replies

7. Shell Programming and Scripting

Read values from a file

Hi , I have a file with the following content I need the read the year and reporting from this file and store them in variables. I understand that we can read the file delimited by'=' but not sure how to extract the values correctly. Thanks in advance Regards (3 Replies)
Discussion started by: w020637
3 Replies

8. Shell Programming and Scripting

how to read only the first two values from a file in unix

Hi, I'm new to unix.. I need to read only the first two values from a file that contains many data....My record is like this FTG_ver_num=7.0 RUN_ID=2 $$tgt_envrnmt_cd=FTG $$WRK_FLW_CD=NPL I need oly the values of ETG_ver_num and RUN_ID. i.e) output to be 7.0 and 2 The code i used... (2 Replies)
Discussion started by: raghulshekar
2 Replies

9. Shell Programming and Scripting

how do I pass or read values from file ?

Hi one & All , My Need is to Create 64 Partition and create File System in Linux. I have the Script ... for((a=0;a<=63;a++)) do fdisk /dev/cciss/c0d$a done for((a=0;a<=63;a++)) do mkfs.ext2 /dec/cciss/'c0d'$a'p1' done the moment I run the Script I get the Prompt ... Command... (1 Reply)
Discussion started by: nix-kid
1 Replies

10. UNIX for Dummies Questions & Answers

How can I read variable values from file?

Hi, I want to pratmeterze my scripts like, my confRsync file contains varibale values for 1. host 2. Destination and 3. source like this, I want to read this values from this and assing to my makeRsyn.sh file's varibales. how to do this? (1 Reply)
Discussion started by: redlotus72
1 Replies
Login or Register to Ask a Question