Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

shell iterate over lines in variable

#!/bin/bash
#Try to iterate over each line
echo "For loop:"
for item in $list
do
        echo "Item: $item"
done
#Output the variable to a file
echo -e $list > list.txt

#Try to iterate over each line from the cat command
echo "For loop over command output:"
for item in `cat list.txt`
do
        echo "Item: $item"
done
Source by superuser.com #
 
PREVIOUS NEXT
Tagged: #shell #iterate #lines #variable
ADD COMMENT
Topic
Name
7+7 =