⇤ ← Revision 1 as of 2008-04-08 23:25:13
1196
Comment:
|
1200
split the first two examples
|
Deletions are marked like this. | Additions are marked like this. |
Line 9: | Line 9: |
while read host do |
}}} {{{ while read host; do |
Line 25: | Line 25: |
The ssh example can be fixed the same way, or with the `-n` switch (at least with `openssh`). | The ssh example can be fixed the same way, or with the `-n` switch (at least with OpenSSH). |
I'm using a loop which runs once per line of input but it only seems to run once; everything after the first line is ignored?
Typically you'll see this behaviour in situations like these:
while IFS= read -r file; do ffmpeg -i "$file" -vcodec libxvid -acodec libfaac -ar 32000 "${file%.avi}".mkv done < <(find . -name '*.avi')
while read host; do ssh "$host" command done <hostslist
What's happening here? Let's take the first example. read reads a line from standard input (FD 0), puts it in the file parameter, and then ffmpeg is executed. Like any program you execute from BASH, ffmpeg inherits standard input, which for some reason it reads. I don't know why. Here's how you make it work:
while IFS= read -r file; do ffmpeg </dev/null -i "$file" -vcodec libxvid -acodec libfaac -ar 32000 "${file%.avi}".mkv done < <(find . -name '*.avi')
Notice the redirection on the ffmpeg line: </dev/null. See the [:BashGuide#Redirection:redirection section] of the BASH Guide for more information on this.
The ssh example can be fixed the same way, or with the -n switch (at least with OpenSSH).