0

I seem to be having some problems executing this script? not sure what is causing the problem?

touch file
cat file | while read line; 
do
output=$(awk '/path/ {print NR, $0}' "$line");
if [$(#output) -ne 0];
then
echo "File: " "$line";
echo "----------------------------------------------------";
echo "$output"
else
echo "No keyword appeared";
fi
done
asd
  • 9
  • 1
    check on [shellcheck.net](https://www.shellcheck.net/) – kyodev Apr 05 '18 at 12:59
  • 1
    You need spaces around the brackets in the `if [ condition ]` (`[` and `]` need to be parsed as separate tokens, which won't happen if they're next to other characters) – Aaron Apr 05 '18 at 13:00

1 Answers1

1

Based on shellcheck.net

Line 5:

if [$(#output) -ne 0];
   ^-- SC1035: You need a space after the [ and before the ].
   ^-- SC1009: The mentioned syntax error was in this test expression.
    ^-- SC1073: Couldn't parse this command expansion. Fix to allow more checks.

Line 6:

then
    ^-- SC1072: Unexpected keyword/token. Fix any mentioned problems and try again.
Gerald Hughes
  • 4,710
  • 14
  • 59
  • 105