Find the answer to your Linux question:
Results 1 to 5 of 5
Originally Posted by Gekitsuu you should be able to do NEWSTRING=$STRING1$STRING2 it works but i can't use it for creating a path variable / file name. e.g. $STRING1 = path ...
  1. #1
    Just Joined!
    Join Date
    Aug 2008
    Posts
    3

    cat $STRING1$STRING2 doesn't work.

    Quote Originally Posted by Gekitsuu View Post
    you should be able to do NEWSTRING=$STRING1$STRING2
    it works but i can't use it for creating a path variable / file name.

    e.g.
    $STRING1 = path
    $STRING2 = filename

    cat $STRING1$STRING2 will not work.

    so how to get this working?
    thanks,
    Sachin

  2. #2
    Just Joined! DT0X's Avatar
    Join Date
    Nov 2008
    Location
    Southwest UK
    Posts
    31
    Are you bash scripting?

    You dont use the "$" in front of the variable name when you assign it, only when you use it - the following script will print the contents of /etc/resolv.conf:

    #!/bin/bash

    STRING1="/etc/"
    STRING2="resolv.conf"

    cat $STRING1$STRING2

  3. #3
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,316
    Quote Originally Posted by sachinpandhare
    $STRING1 = path
    $STRING2 = filename
    There shouldn't be any space before and after equal to = sign.
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  4. #4
    Just Joined! DT0X's Avatar
    Join Date
    Nov 2008
    Location
    Southwest UK
    Posts
    31
    Should have categorically stated that in my post / code correction too (even though I did fix that point too) - cheers casper, I just assumed it was a typo - although you didnt mention the other fundamental bug I noted above, i.e. the inclusion of the $ when declaring vars

  5. #5
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,316
    Quote Originally Posted by DT0X
    although you didnt mention the other fundamental bug I noted above, i.e. the inclusion of the $ when declaring vars
    I checked this thread after you and didn't want to repeat your suggestion.
    I just added one more point in your suggestion.
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...