(According to the gospel of Tim Leslie)
$ "start": "/bin/sh -c 'cd projects/${1:-$0} && yarn start' basic"
$ npm run start basic
${1:-$0}
<-- This says “use $1 as the project directory if given, otherwise use $0”.- Adding
basic
to the end of the command ensure that$0
is alwaysbasic
and then$1
will always be whatever the user types on the command line. e.g.bolt start login
=>$1 = login
. - We can’t use
${0:-basic}
to get the defaults, because if the user doesn’t supply an argument, rather than$0
being unset, it gets set to/bin/sh
, which doesn’t particularly help.
Some light reading: http://wiki.bash-hackers.org/syntax/pe#parameter_expansion