PDA

View Full Version : Bash script - concatenation woes




hiddenpremise
May 26, 2009, 02:53 PM
I am trying to take my computer's name and pass it in the query line of a url. So far I can get the computer name, but I can't get the URL to assign to a variable.
This is what I wrote
BASEURL="http://isis/db.php?compname="
COMPNAME= /usr/sbin/networksetup -getcomputername
FINAL= ${BASEURL}${COMPNAME}
curl $FINAL

This is the output I get
testdb.sh: line 4: http://isis/db.php?compname=: No such file or directory


Any ideas?



lee1210
May 26, 2009, 03:05 PM
COMPNAME=`/usr/sbin/networksetup -getcomputername`

Those are backticks. On a US keyboard this shared the ~ key next to the 1 key.

-Lee

EDIT: Not sure if this will fix the error you are getting, though...

pilotError
May 26, 2009, 03:40 PM
You can do the following:


MYURL="http://isis/db.php?compname=${HOSTNAME}"
curl $MYURL

hiddenpremise
May 27, 2009, 07:06 AM
Thanks guys! Yall have been a great help!