I'm beginner in bash scripting and I'm having trouble with following script.
I want to process all given arguments from stdin. Then I check, if these arguments are ordinary text files. If yes, I want to store them into the array and later I want to go through the whole array. But I am getting an error : word unexpexted on the line with files+=("$@") I've tried to write it like this files=("$@") but then I get following error on the line : "(" unexpected (expecting "fi")
I would be really grateful for any advice. Thank you in advance.
for file in "${argv[@]}"; do
if [ -d "$file" ]
then
echo "Error: '"$file"' is directory!" > /dev/stderr
continue
fi
if [[! -f "$file"] || [! -r "$file"]]
then
echo "Error: '"$file"'!" > /dev/stderr
continue
fi
file "$file" | grep text >& /dev/null
if [ ! $status ]
then
files+=("$@")
else
echo "Error: '"$file"' not a text file!" > /dev/stderr
fi
done
for file in "${files[@]}"; do
# .....
done
if command, notcommand; if [ ....