bash - Test if user passed in a shell variable -


i have shell function check if user passed in second variable. have tried not seem working

function dash() {     if [ -z "$2" ];         open dash://$1:$2;     else         open dash://$1;     fi } 

basically, want if second argument $2 passed in 'x' else 'y'

just do:

function dash() {   open dash://$1${2+:}$2 } 

the ${2+:} expands : if $2 set, , null string otherwise.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -