Let's pretend I'm running something like this:
jq -nr --arg target /tmp \'(["echo","Hello, world"]|@sh)+">\($target)/sample.txt"' \| shEverything is fine unless I forgot to pass variable $target:
$ jq -nr '(["echo","Hello, world"]|@sh)+">\($target)/sample.txt"'jq: error: $target is not defined at <top-level>, line 1:(["echo","Hello, world"]|@sh)+">\($target)/sample.txt"jq: 1 compile errorHow can I catch this and use default value?
I've tried:
$target?($target)?try $target catch null$target? // null
But it seems to be parsing-time error, which obviously can't be caught at runtime. Have I've missed any dynamic syntax?
I've found that command-line arguments can be found in $ARGS.name, but there are two drawbacks:
- This was introduced in version 1.6, but I have 1.5 on CentOS 7.
- It doesn't catch locally defined variables.