2

I took this code from a script I found online :

[ $# = 0 ] && usage

If there are no parameters at the command line, then call the usage method (which print the help info).

The thing I don't understand is why does the script exits after calling usage? Shouldn't it simply continue to other code?

2 Answers 2

2

There are multiple ways this can happen:

  1. The usage method has an exit command in it
  2. The usage method has a return 1 command (or other non-zero value) and the script is invoked with -e flag, for example #!/bin/sh -e shebang
  3. The usage method has an operation that fails and the script is invoked with -e flag

Maybe there are more ways that I don't recall now.

Personally, I always use exit 1 as the last command in a usage method, so the behavior seems all natural to me.

Sign up to request clarification or add additional context in comments.

Comments

2

It would carry on unless 'usage' executes 'exit' command

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.