I have some shell codes looks like:
JavaScript
x
while read line; do echo $line; done < (ls -la $path)
but, get an error “-bash: syntax error near unexpected token `(‘” which i can’t fix it. I do know the pipeline command can also do it well. likes
JavaScript
ls -la $path | while read line; do echo $line; done
but actually I wish to do something in the loops like change the global value
JavaScript
while read line; $((count++)); done
and the pipeline didn’t work.
Advertisement
Answer
The correct syntax for process substitution is:
JavaScript
while read line; do echo $line; done < <(ls -la $path)
But anyways, doing it this way is not a good idea at all, use a for loop instead:
JavaScript
for fname in "$path"/* "$path"/.*; do
echo "$fname"
done
And if you need to get information about a file in the loop, use stat.