You missed one of the really great BASHisms: <( COMMAND ). Basically, run command in a subshell, then return it's output through a file-descriptor. Meaning that you can do things like:
<( COMMAND )
Another great one is VAR=($( COMMAND )) ...which takes the output from COMMAND and creates an array-variable from it.
VAR=($( COMMAND ))
Also useful is $( COMMAND )$? for when you care about how a command exited but not its output (e.g., you want to test to see if grep found a string in a file, [[ $( grep -q PATTERN FILE )$? ]].
$( COMMAND )$?
[[ $( grep -q PATTERN FILE )$? ]]
These are great! When I get in front of a keyboard, I’ll add them to the list! Thanks for sharing. What are the most common file-expecting commands you use the sub shell redirect with?
AWS CLI for (particularly for CloudFormation) seems to not quite process STDIN for the --parameters flag as one might expect. Usually have to do something like what I put in my article when I'm doing stack-iterations as part of a quick test-change-test cycle (where "quick" is relative to things like RDS - there's frequently not enough time to wait for one launch to delete before moving on to the next launch).
Thanks again for the tips! I just wanted to let you know that I updated the article with your suggestions. 😀
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.