Thursday, May 16, 2019

How do you process the output of a command in the shell line-by-line?

Answer


Answer




I need to process the shared library dependencies of a library from a bash script. The for command processes word-by-word:




for DEPENDENCY in `otool -L MyApplication | sed 1d`
do
...
done


What is the way to process the results line-by-line?


Answer



You should use the read command.




otool -L MyApplication | sed 1d | \
while read i
do
echo "line: " $i
done


See bashref for a description of the read builtin, and its options. You can also have a look at the following tutorial for examples of using read in conjunction with for.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...