I am looking for a test expression with a usage message. When I enter in command line a file such as ./file I need the script to stop and echo error. When I enter ./file test I need the file to run and enter file. I am having a hard time using test expression message. So far I have this and it sort of does what I want it to but I need to check and make sure ./file test is actually input to enter file. if it's not input at command properly it should spit an error and exit.

   if [$# -eq 0 ]
      exit 1

[ is a command; [$# is not. You need to separate a command from its arguments:

if [ $# -eq 0 ]; then
    echo "error"   # Here, too
    exit 1

Incidentally, you can replace that whole block with a special parameter expansion:

: ${1?error}

If the first positional parameter isn't set (i.e., there are no positional parameters), print the message following the ? and exit.

  • Im lost sorry for my ignorance I don't understand
    – jake
    Nov 14 '15 at 19:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.