0

so for starters i have the following, main process im running

for fname in (filename); do  
  ./$comma "$fname" (var1) (var2)  
  mv "$fname" "${fname}.fin"  
done  

then i have a listfile of names looking like:

filename|var1|var2   
file1|9|1  
file2|8|3  

etc...

would like to set it up where - when the master script goes to run the ./$comma script it reads from the listfile and populate the fname, var1, and var2 (per piped order) - right now i have a lot of repeated chunks of script like the above and would like to consolidate or clean it up for sure. Any help is appreciated - doesnt necessarily have to be a for;do loop - just as long as the script is ran on the right file with right args and gets renamed.

2
  • Don't Read Lines With For Commented Mar 2, 2017 at 17:51
  • Thank you for this link - definitely helpful moving forward! Commented Mar 2, 2017 at 18:11

1 Answer 1

2

The for loop you show isn't syntactically correct. You want a while loop, though, that uses the read command.

while IFS="|" read -r fname var1 var2; do
  ./"$comma" "$fname" "$var1" "$var2"
  mv "$fname" "$fname.fin"
done < filenames.txt
Sign up to request clarification or add additional context in comments.

2 Comments

thank you so much, I do understand it wasnt syntactically correct for a reading of a file it was more a quick fix that turned into a frankenstein of a script.
I do want to ask - will this run always for every line in the filenames.txt? or will it "skip" those files that are not present when its being ran? cd "$ftf" while IFS="|" read -r fname var1 var2; do echo " Processing Comma MFIX: $fname" >> "$logfile" ./"$comma" "$fname" "$var1" "$var2" mv "$fname" "$fname.fin" done < comma_strlst.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.