Hacker News new | ask | show | jobs
by flukus 2716 days ago
It's not as nice, "cat $today" is easier to type than "cat $(today)" and would give better completion, just declared matching variables instead of matching functions, files and executables.

On the plus side, TIL the subshell syntax plays well with eval/expand shortcut (ctrl+alt+e).

3 comments

Wouldn't "cat $today" result with "cat: No such file or directory: 2019-01-08"? Did you mean echo instead of cat?
My real life use case for these dynamic variables would be more like "cat/vim/cp $log" to get today's log file which would expand to something like /somedir/logs/201901/09/product.log. Handy when you have a large matrix of products/environments.
Only in the case when no such file exists in the current directory :)
* "cat $today" is easier to type than "cat $(today)"*

Except you should really be in the habit of typing "cat ${today}" ;)

Except you should really be in the habit of typing `cat "${today}"` ;) Quote everything!
Why? The {} doesn't prevent glob expansion or field separation.
It's not obvious that just expanding a variable runs code though.