0

i am building a bash script that is supposed to put each line of the output of one command to an variable and then run some commands on that, i am doing it like

for i in `cmd`
do 
echo i=$i
lang=$(echo $i | cut -d '"' -f 6)
echo lang=$lang
#some stuff
done

my problem is that for is using space and newlines for separation to different $i's and i want it to do create only new $i's with newline delimiters cause every line may have a cupple of spaces and i want them no matter that handled as it own...

google but found nothing really helping me, only suggestions to use xargs which dosnt help me cause i need to use not one command but a cupple after creating some variables and running some if statements that desiside which command is to run if any...

nanderer
  • 9
  • 1

1 Answers1

0

If you want to read cmd's output line by line you can do it using while loop and bash's internal read command

cmd | while IFS= read -r i
do 
    echo "i=${i}"
    lang="$(echo "${i}" | cut -d '"' -f 6)"
    echo "lang=${lang}"
    #some stuff
done

Use " around a variable's de-reference to avoid problems with spaces inside it's value.

Glushiator
  • 630
  • 8
  • 8