1

I have a bash upload script which looks like this -

if [ $# -lt 2 ] 
then
   echo usage: $0 /path/to/mvn /path/to/libs [procs] [groupId]
fi

MVN_EXE=$1
LIB_DIR=$2
PROCS=10
GROUPID=$4:-'default'

if [ $# -gt 2 ] 
then
  PROCS=$3
fi

I want the GROUPID to be the 4th arg or to be set automatically to 'default'. Could I be advised on the correct syntax for this? A google search has given me this so far. Would I then need to add an additional if search along the lines of -

if [$# -gt 3]
then
PROCS=$3
GROUPID=$4
fi

or just replace the original if statement with the new version?

Thanks

2 Answers 2

4

You just forgot the curly braces. You can use them to avoid the final if statement too:

if [ $# -lt 2 ] 
then
   echo usage: $0 /path/to/mvn /path/to/libs [procs] [groupId]
fi

MVN_EXE=$1
LIB_DIR=$2
PROCS=${3:-10}
GROUPID=${4:-'default'}
Sign up to request clarification or add additional context in comments.

Comments

0

Correct syntax is:

GROUPID=${4:-'default'}

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.