Sunday, December 1, 2019

Bash Command Arguments ${...}



I noticed this type of command argument in a bash script:



node ${debug?--nocrankshaft --nolazy --nodead_code_elimination --debug-brk=15454} app.js


I am wondering what ${....} means?




How is it used?



Also, is there a good source out there that discusses all the different variations of argument commands for bash?



What you seeing here is parameter expansion, which can be thought of as a set of methods used by bash as shortcuts to evaluating variables (aka parameters). In this specific case we are dealing with the following structure:



${parameter:?word}
Display Error if Null or Unset. If
parameter is null or unset, the expan‐
sion 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 param‐
eter is substituted.


( taken from man bash )



In short, if a variable is unset or doesn't exist, throw an error, like so:




xieerqi:$ echo ${NOTSET?this param not set}          
mksh: NOTSET: this param not set


If variable is set, do nothing



xieerqi:$ echo ${PWD?this param not set}             
/home/xieerqi



In your specific case , debug parameter is to be passed to node , and if it's not set, show the user what values should it be set to, namely --nocrankshaft --nolazy --nodead_code_elimination --debug-brk=15454


No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...