-1

I am writing a bash script and i need to run the following command, but i can't seem to figure out how to get it to run, since i need both pairs of commands to be within back tics. Below is the code i am trying to run.

VERSION=`getserversion.py` |grep `getcliversion.py`

So the first part, gets the version running on server, the second part, gets the version running for the client, just trying to see if they match, but i can't get both the commands to run, i keep getting bash errors when i try to run this.

  • This is not a great approach. You should probably assign variables and compare them: `server=$(getserversion.py); client=$(getcliversion.py); if [ "$server" != "$client" ]; then echo "Mismatch: $server vs $client"; fi` – that other guy Jan 25 '21 at 17:32

1 Answers1

1

Two possible paths here: split the command into two parts, and use BASH to compare, or write a composite line. Either way, better to use the $(command) instead of backticks.

Splitting the command

SVC_VER=$(getserversion.py)
CLI_VER=$(getcliversion.py)
if [ "$SVC_VER" = "$CLI_VER" ] ; then
   ...
fi

Or, combining them into single command line

MATCH=$(getversions.py | grep $(getcliversion.py))

Note that it's not possible to use the backticks for the second command, as the back ticks do not support nesting of commands.

dash-o
  • 13,723
  • 1
  • 10
  • 37
  • 2
    It's _possible_ to nest with backticks, it's just messy (involves backslashes... the number of them multiplying with nesting depth). – Charles Duffy Jan 25 '21 at 17:34
  • 2
    BTW, I'd suggest quoting: `grep -e "$(getcliversion.py)"`, so the output can't be split into multiple `grep` arguments, some of which would likely be interpreted as filenames to read. – Charles Duffy Jan 25 '21 at 17:35