0

When I read some tutorial today, I came over with the statements like ${file?my.file.txt} and ${file:?my.file.txt}, what do ${file?my.file.txt} and ${file:?my.file.txt} mean in Bash script?

2
  • For your future questions, please do a little research before. I've seen you've asked a bit about Bash in particular, but your questions are hardly based on an actual problem and somewhat lack demonstration of research effort.
    – slhck
    Oct 5, 2014 at 15:41
  • @slhck Ok. In fact, I just wanna know the specific details. Sorry for that if it conflicts with the style here. Thanks for the patient answers, anyhow. Oct 5, 2014 at 15:48

1 Answer 1

3

From the manual – and it's always good to check that first:

${parameter:?word}

If parameter is null or unset, the expansion of word (or a message to that effect if word is not present) is written to the standard error and the shell, if it is not interactive, exits. Otherwise, the value of parameter is substituted.

So, it's a safeguard against unset variables, where you could show an error. Also,

Omitting the colon results in a test only for a parameter that is unset. Put another way, if the colon is included, the operator tests for both parameter’s existence and that its value is not null; if the colon is omitted, the operator tests only for existence.

But of course, the examples you gave are somewhat arbitrary and I wonder why the tutorial would even include them, let alone including them but not explaining what they do.

1
  • After I make all these things clear, I will write a really high quality doc. Thx! Oct 5, 2014 at 16:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .