I have a command which generates the following output:
Code:
$ sudo vnconfig -l
vnd0: not in use
vnd1: not in use
vnd2: not in use
vnd3: not in use
$
I would like to find the first
vnd device which is not in use.
- The following is a nice first try...
Code:
$ echo $(sudo vnconfig -l) | grep 'not in use'
vnd0: not in use vnd1: not in use vnd2: not in use vnd3: not in use
...but all lines are concatenated together.
- The following seems reasonable, but the results are far worse:
Code:
$ cat test.sh
#!/bin/sh
for LINE in $(vnconfig -l) ; do
echo $LINE
done
$ sudo sh test.sh
vnd0:
not
in
use
...
$
- Reading the output line-by-line would be ideal, but so far my foo is weak:
Code:
$ cat test.sh
#!/bin/sh
while read LINE ; do
echo $LINE
done < $(vnconfig -l)
$ sudo sh test.sh
test.sh[5]: cannot open vnd0: not in use
vnd1: not in use
vnd2: not in use
vnd3: not in use: No such file or directory
$
Is there a way to read the command's output line-by-line without resorting to redirecting output into a temporary file?
Thanks.