I have been writing a large script with many functions inside it.
At one point I had need to capture some text data and print to the screen.
I was surprised by the results I got and after some research time decided to change tactics.
Meaning I used another method to get the results I need.
However now that the script is finished and working I went back to my "for loop" issue to see if
I could figure out a way to make this work for future uses.
Maybe what I want/expect is not possible in this case?
It seems that "for" is parsing each item in the text file with space/tab separations.
I expected "new line" as the parse for each item.
I have two files:
1. Simple text file containing multiple lines.
Each line contains a command with arguments
2. A script that uses this text file
Text file = list.txt
Here is a two line sample
cat list.txt
./syncNode.sh ndm_${CELL} $PORT
./syncNode.sh ndm_${CELL}q $PORT
Script file = script.ksh
for i in `cat list.txt`
do
echo ""
echo "$i"
done
output of script.ksh
./syncNode.sh
ndm_${CELL}
$PORT
./syncNode.sh
ndm_${CELL}q
$PORT
Results I expected:
./syncNode.sh ndm_${CELL} $PORT
./syncNode.sh ndm_${CELL}q $PORT
Now I know in my example above the "for" loop is redundant as I could just cat the file.
However in my original script I was trying some more complex things inside the loop.
The "for" loop was NOT my best option, but at the time seemed prudent.
I was surprised at the output I got and now it is just a curiosity, not a needed exercise.
I am not looking for another way to accomplish, just like to learn how/why I got unexpected results.
The best I can figure is "for" ignores the carriage return and treats the file no different from:
for i in "1 2 3 4 5"
Be glad to hear any thoughts.
Thankx
As always we thank you for your support
Doug
At one point I had need to capture some text data and print to the screen.
I was surprised by the results I got and after some research time decided to change tactics.
Meaning I used another method to get the results I need.
However now that the script is finished and working I went back to my "for loop" issue to see if
I could figure out a way to make this work for future uses.
Maybe what I want/expect is not possible in this case?
It seems that "for" is parsing each item in the text file with space/tab separations.
I expected "new line" as the parse for each item.
I have two files:
1. Simple text file containing multiple lines.
Each line contains a command with arguments
2. A script that uses this text file
Text file = list.txt
Here is a two line sample
cat list.txt
./syncNode.sh ndm_${CELL} $PORT
./syncNode.sh ndm_${CELL}q $PORT
Script file = script.ksh
for i in `cat list.txt`
do
echo ""
echo "$i"
done
output of script.ksh
./syncNode.sh
ndm_${CELL}
$PORT
./syncNode.sh
ndm_${CELL}q
$PORT
Results I expected:
./syncNode.sh ndm_${CELL} $PORT
./syncNode.sh ndm_${CELL}q $PORT
Now I know in my example above the "for" loop is redundant as I could just cat the file.
However in my original script I was trying some more complex things inside the loop.
The "for" loop was NOT my best option, but at the time seemed prudent.
I was surprised at the output I got and now it is just a curiosity, not a needed exercise.
I am not looking for another way to accomplish, just like to learn how/why I got unexpected results.
The best I can figure is "for" ignores the carriage return and treats the file no different from:
for i in "1 2 3 4 5"
Be glad to hear any thoughts.
Thankx
As always we thank you for your support
Doug