I know I can do:
echo ${var:-4}
to print 4 if var is null,
but how to assign -n in this case..?
echo ${var:--n} does not work.
although this does work..
echo ${var:---n}
but in that case it prints out --n and I need it to print -n.
I know I can do:
echo ${var:-4}
to print 4 if var is null,
but how to assign -n in this case..?
echo ${var:--n} does not work.
although this does work..
echo ${var:---n}
but in that case it prints out --n and I need it to print -n.
The problem is not in the default, but in echo: -n has a special meaning for it (check help echo). Use printf instead:
printf '%s\n' "${var:--n}"