0

I am new to scripting and using linux. The below script that I have written simply prints the passed arguments and does a check in if condition. But not sure why I keep getting 'if' unmatched error

echo "The number of arguments passed "
echo $#;
echo "The passed arguments are "
echo $@

count="$#"

echo "Count is "
echo $count;

if [[ $count -eq "2" ]]; then
   echo "Correct";
else
   echo "Incorrect";
fi

when I run script above as

$ ./MyScript "ABC" "XYZ"

Output ->

The number of arguments passed
: not found [No such file or directory]
2
The passed arguments are
: not found [No such file or directory]
ABC XYZ
: not found [No such file or directory]
Count is 
: not found [No such file or directory]
2
syntax error 'if' unmatched
Nichole
  • 189
  • 2
  • 7
  • 1
    How are you running the file? – Maroun Feb 09 '23 at 08:46
  • Does your file have incorrect line endings (msdos crlf)? It should only have unix style line endings (lf). Check the file with a different editor (example vi). – mao Feb 09 '23 at 08:50

0 Answers0