-2

I need to create a script that uses an 'if' command that checks whether there is exactly one argument. If there is more than one argument, I need it to echo “Usage: give exactly 1 argument, the string to be looked for” and then exit immediately.

  • 2
    Does this answer your question? [Check number of arguments passed to a Bash script](https://stackoverflow.com/questions/18568706/check-number-of-arguments-passed-to-a-bash-script) – Freddy Apr 05 '20 at 22:41

1 Answers1

1

Welcome to Stackoverflow.

This should do the trick:

if [ "$#" -gt 1 ]; then
    echo "Usage: give exactly 1 argument, the string to be looked for"
    exit 0
else
   echo the expected processing happens in this section of this code
fi
Mamun
  • 2,322
  • 4
  • 27
  • 41