1

I have specified a variable like this in shell script,

organisation="${organisation:-'$1/'}" 

I have passed $1 as "repo" while executing this script, then organisation variable is echoed as "repo/". without passing $1 it's "/", Which i don't want.

My Question is i want this variable to print null if $1 is not passed or print "repo/" if $1 is passed.

1 Answer 1

1

This will assign organization to $1/ if $1 was passed to the script and set it to empty otherwise:

[ "$1" ] && organization=$1/ || organization= 

[ "$1" ] tests to see if $1 is empty or not. If it is not empty, then [ "$1" ] returns true and the command after && is executed. If it is false, the command after || is executed.

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.