2

I want to check if the user has given the script any arguments and if this is the case, the script should close.

if [ $@ = "" ]; then exit fi 

is not working.

2
  • 1
    The number of arguments are stored in the variable $# Commented Jan 21, 2016 at 13:39
  • Note, the reason this doesn't work, is that you need to put double quotes around $@ because of how bash handles empty strings. Unquoted, the first line becomes if [ = "" ]; then when no arguments are passed in, which results in a syntax error. Quoted, you have if [ "" = "" ]; then, which is treated as expected. Commented Oct 4, 2017 at 6:02

1 Answer 1

2

You can try like this,

if [ "$#" -eq 0 ]; then echo "Illegal number of parameters" fi 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.