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?
The shell parses the command line and finds the program to execute. It passes any options and arguments to the program as part of a new process for the command such as ps above. While the process is running ps above the shell waits for the process to complete.
In Bash, you can use a while loop on the command line to read each line of text from a file and do something with it. Our text file is called “data. txt.” It holds a list of the months of the year. The while loop reads a line from the file, and the execution flow of the little program passes to the body of the loop.
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
.
otool -L MyApplication | sed 1d | while read line ; do # do stuff with $line done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With