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.
echois literally allowed to do anything when passed-nas an argument. See the POSIX specification: "If the first operand is-n, or if any of the operands contain a backslash ( '\' ) character, the results are implementation-defined". When passed-n, or any content with literal backslashes,echocould turn a backflip or kill your cat and still be POSIX-compliant. Follow the advice in the APPLICATION USAGE section of the spec, and useprintfinstead.