0

I'm starting to learn how to script bash and I've run into a problem with the echo command and a variable.

#!/bin/bash
LOGINOUTPUT = "`wget --no-check-certificate --post-data 'login=redacted&password=redacted' https://nessusserver:8834/login -O -`"
echo $LOGINOUTPUT

Running this script returns the following:

--2013-08-15 15:07:32--  https://nessusserver:8834/login
Resolving nessussserver (nessusserver)... 172.23.80.88
Connecting to nessusserver (nessusserver)|172.23.80.88|:8834... connected.
WARNING: cannot verify nessusserver's certificate, issued by ‘/C=FR/ST=none/L=Paris/O=Nessus Users United/OU=Certification Authority for nessusserver.healthds.com/CN=nessusserver.healthds.com/emailAddress=ca@besecmisc1.healthds.com’:
  Unable to locally verify the issuer's authority.
    WARNING: certificate common name ‘nessusserver.healthds.com’ doesn't match requested host name ‘nessusserver’.
HTTP request sent, awaiting response... 200 OK
Length: 461 [text/xml]
Saving to: ‘STDOUT’

100%[=============================================================================================================================================================>] 461         --.-K/s   in 0s      

2013-08-15 15:07:33 (90.4 MB/s) - written to stdout [461/461]

./nessus-output.sh: line 2: LOGINOUTPUT: command not found

Why does it think that LOGINOUTPUT is a command? Thanks in advance for any help!

EDIT: Updated script

#!/bin/bash
LOGINOUTPUT=$(wget --no-check-certificate --post-data 'login=redacted&password=redacted' https://nessusserver:8834/login -O -)
echo $LOGINOUTPUT

Still yields the same error, same if I leave $(...) as backticks.

avorum
  • 2,243
  • 10
  • 39
  • 49
  • Look again. You should be getting a different error (if any) – user000001 Aug 15 '13 at 19:29
  • As far as I can tell it's the same, the line with the error still says ./nessus-output.sh: line 2: LOGINOUTPUT: command not found – avorum Aug 15 '13 at 19:39
  • After some investigation I've found that deleting the assignment to wget and replacing it with an assignment to $(ls -la) doesn't change the output either. For some reason new builds of the script aren't catching. – avorum Aug 15 '13 at 19:47

1 Answers1

3

This happens because you have spaces before and after the = in the variable assignment. The correct assignment is:

LOGINOUTPUT="....

with no spaces.

If you add spaces, then the shell interprets LOGINOUTPUT as a command, and tries to pass it two arguments: the "=" and the the quoted string. This of course fails, with the error LOGINOUTPUT: command not found

As a sidenote, it is better to use this syntax $(command) than backticks when doing process substitution.

user000001
  • 32,226
  • 12
  • 81
  • 108