This question already has an answer here:

I saw this in the end of an awesome shell script but I can't understand the login here because I think it's being short-handed for a longer command.

spark ${@:-`cat`}

This apears at the end of this script. Any ideas?

+ Marks for some one who extends it into a full segment of code, even if its slower (Better for explanation)

marked as duplicate by Stephen Kitt, slm bash Jun 1 '16 at 11:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


It's the first special case of parameter substitution in man bash:

Use Default Values. If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted.

In the case you mentioned, either the user has provided arguments on the command line and they will be used, or the user is asked to input them on standard input afterwards.


Afaik :- is basically: use $@ OR `cat` ( without setting $@ to `cat` )...

so some variable substition thingy...

Edit: So it gives you some sort of interactive input...

Here's a little Terminal test:

localhost:~ _druu$ echo ${@:-`cat`}
^\hello world ;)
localhost:~ _druu$ 

Not the answer you're looking for? Browse other questions tagged or ask your own question.