Bash script - concatenation woes

Discussion in 'Mac Programming' started by hiddenpremise, May 26, 2009.

  1. macrumors regular

    hiddenpremise

    Joined:
    Jul 25, 2008
    Location:
    Somewhere between my imagination and reality
    #1
    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
    Code:
    BASEURL="http://isis/db.php?compname="
    COMPNAME= /usr/sbin/networksetup -getcomputername
    FINAL= ${BASEURL}${COMPNAME}
    curl $FINAL
    This is the output I get
    Code:
    testdb.sh: line 4: http://isis/db.php?compname=: No such file or directory
    
    Any ideas?
     
  2. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    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...
     
  3. macrumors 68020

    pilotError

    Joined:
    Apr 12, 2006
    Location:
    Long Island
    #3
    You can do the following:

    Code:
    MYURL="http://isis/db.php?compname=${HOSTNAME}"
    curl $MYURL
    
     
  4. thread starter macrumors regular

    hiddenpremise

    Joined:
    Jul 25, 2008
    Location:
    Somewhere between my imagination and reality

Share This Page