I have some shell codes looks like:
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
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
while read line; $((count++)); done
and the pipeline didn’t work.
Advertisement
Answer
The correct syntax for process substitution is:
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:
for fname in "$path"/* "$path"/.*; do echo "$fname" done
And if you need to get information about a file in the loop, use stat.