in a bash script I call an external script that gives me the status of a program, like
~/bin/status
which returns something like
program is running
or
program is halted
Now I want to use only the last word, which I get e.g. with
STATUS=$(~/bin/status)
echo ${STATUS##* }
which gives me 'running' or 'halted', so far so good.
What I wonder is, is there a way to do this without storing the output of the status-script in a variable? I mean something like
echo ${$(~/bin/status)##* }
or
echo ${(~/bin/status)##* }
This call returns an error message 'bad substitution'. I've already searched for a solution but didn't find any. Maybe here is some bash specialist who can answer this? And no, it is not really a problem to do this with a variable, I'm just curious :-).
echo $( ~/bin/status | sed 's/.* //g' )~/bin/statuswould rather (even additionally) return an exit code of0or non-0, so you could simply have your own script doif ~/bin/status; then …. You'd also get the actual exit code for free in the$?special variable.