CaptainMark
June 26th, 2012, 02:02 PM
This is probably simple for most here but I'm still learning so please be patient.
I have a script that I've been practising on for a while, which stores some basic settings just in a text file and my script will read the variables from the text to remember them from last time, here it is currently:
if [ -e $targets ]; then
read source destination < $targets
else .....
The variable $targets contains the location of the text file so this part takes the first two words from the text file and assigns them as the variables $source and $destination (which are also file paths) my problem is that I want to change it so its the first two lines that get assigned to variables not the first two words, so if the $source and $destination can contain spaces.
I thought this would work
if [ -e $targets ]; then
IFS=$'\n'
read source destination < $targets
unset IFS
fi
the first variable comes out as expected the complete first line of the text file including spaces, however the second variable does not read the second line but comes out blank.
Could someone help me realise my mistake and point out what I'm missing so I can correct my script,
Thanks
Mark
I have a script that I've been practising on for a while, which stores some basic settings just in a text file and my script will read the variables from the text to remember them from last time, here it is currently:
if [ -e $targets ]; then
read source destination < $targets
else .....
The variable $targets contains the location of the text file so this part takes the first two words from the text file and assigns them as the variables $source and $destination (which are also file paths) my problem is that I want to change it so its the first two lines that get assigned to variables not the first two words, so if the $source and $destination can contain spaces.
I thought this would work
if [ -e $targets ]; then
IFS=$'\n'
read source destination < $targets
unset IFS
fi
the first variable comes out as expected the complete first line of the text file including spaces, however the second variable does not read the second line but comes out blank.
Could someone help me realise my mistake and point out what I'm missing so I can correct my script,
Thanks
Mark