Say I have 2 variables that I am assigning as follows:psaux=`ps aux | grep someProcessName`pscount=`ps aux | grep someProcessName | wc -l`I would like to combine the assignments in one line, so that the ps aux | grep someProcessName part is only executed once, so I know there's no possibility something could change in between two executions.The closest I can come is the following grotesque pseudocode:read psaux pscount <<<$(ps aux | grep someProcessName | tee &1 | wc -l)
Multiple variable assignment from different parts of one command pipeline
bash;shell;command substitution
Just re-use the first variable:psaux=$( ps aux | grep someProcessName )pscount=$( printf '%s\n' $psaux | wc -l )The command grep is called only once.The result of such call is re-used to count lines.