variables from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting variables from a file
# 1  
Old 09-10-2002
Question variables from a file

Hi I am trying to write a shell script that will read 4 lines from a file and put them in variables which will be used in the script.
Can someone tell me how can I read a line and put it in a variable?
I have tried this... but this does not work.
#! /bin/sh

cat yest | while read line
do
??? how ho I assign the line to a varible that will persist after the loop and ended?

done

....
# 2  
Old 09-10-2002
You can't do that with sh. sh will run a loop in a subshell. Switch to ksh snd it will work.
# 3  
Old 09-10-2002
no double threads please.

please do not post the same question 2 times. please use your orignal thread.

https://www.unix.com/shell-programming-and-scripting/7988-cat-setting-variables.html
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to call variables from a file to the scripting file?

Let say I have a file with variables (Test1.txt) In Test1.txt file, it consists of Tom is a boy Jim is a dog In the other scripting file (RunTest1.sh), I have #!/bin/ksh filename = /directory/Test1.txt cat $filename for i in $filename do print $i done I managed to call... (1 Reply)
Discussion started by: TestKing
1 Replies

2. Shell Programming and Scripting

How to read each line from input file, assign variables, and echo to output file?

I've got a file that looks like this (spaces before first entries intentional): 12345650-000005000GL140227 ANNUAL HELC FEE EN 22345650-000005000GL140227 ANNUAL HELC FEE EN 32345650-000005000GL140227 ANNUAL HELC FEE EN I want to read through the file line by line,... (6 Replies)
Discussion started by: Scottie1954
6 Replies

3. UNIX for Dummies Questions & Answers

Copy same file with different variables

Hi All, I have same file with like 1xyz_1 ,1xyz_2 , 2ghj_1, 2ghj_2, 4wer_1, 4wer1_2 etc with lots of file having similar type of name. I want to creat folder and copy similar file to that folder. for example folder 1xyz should contain only 1xyz_1 ,1xyz_2. :mad: Thank you in Advance. ... (7 Replies)
Discussion started by: XXLMMN
7 Replies

4. Shell Programming and Scripting

Bash: Reading a file and assigning variables from file

I have a file that has four values on each line and I'd like to give each column a variable name and then use those values in each step of a loop. In bash, I believe you could use a while loop to do this or possibly a cat command, but I am super new to programming and I'm having trouble decoding... (2 Replies)
Discussion started by: ccorder22
2 Replies

5. Shell Programming and Scripting

Reading variables from a file

Hi, I have an issue that hope someone will be able to help me with.... I'm using a while-read loop to read lines from a file that contain variables, and I want the variables substituted, but I can't get it to work - the below example with explain: while read line do echo $line ... (5 Replies)
Discussion started by: AndyG
5 Replies

6. Shell Programming and Scripting

Read file and for each line replace two variables, add strings and save output in another file

Hi All, I have a file, let's call it "info.tmp" that contains data like this .. ABC123456 PCX333445 BCD789833 I need to read "info.tmp" and for each line add strings in a way that the final output is put /logs/ua/dummy.trigger 'AAA00001.FTP.XXX.BLA03A01.xxxxxx(+1)' where XXX... (5 Replies)
Discussion started by: Andy_ARG
5 Replies

7. Programming

How to convert byteArray variables to HexaString variables for Linux?

Hello everybody, I am having problem in converting byte array variables to Hexa String variables for Linux. I have done, converting byte array variables to Hexa String variables for Windows but same function doesn't work for linux. Is there any difference in OS ? The code for Windows is given... (2 Replies)
Discussion started by: ritesh_163
2 Replies

8. UNIX for Dummies Questions & Answers

Writing variables into a new file

echo "Please enter your surname\n" echo "followed by your first name:\c" read name1 name2 echo "Thank you" echo "Now please enter your age" read age echo "Thanks again, we're nearly done. Please enter your town of birth" read town echo "Hi there $name2 $name1" sleep 3 echo "erm..." sleep... (6 Replies)
Discussion started by: phproxy
6 Replies

9. Shell Programming and Scripting

File search variables

I have a remote server that generates files with name format: Daily_Generated_File_11-14-07.txt. The file name remains the same regardless, but the date portion at the end of the name will change (mm-dd-yy). Can someone supply a script that will search for files with the latest date based on... (19 Replies)
Discussion started by: bbbngowc
19 Replies

10. Shell Programming and Scripting

reading from a file and pass as variables and ignore # in the file

file.txt contains ------------------ sat1 1300 #sat2 2400 sat3 sat4 500 sat5 I need to write a shell script that will output like the below #output sat1.ksh 1300 sat3.ksh sat4.ksh 500 sat5.ksh my try ------- (4 Replies)
Discussion started by: konark
4 Replies
Login or Register to Ask a Question