#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0

    How to use Local Variables in unix?


    i have created the below UNIX script to learn how to use Variables, however the output is blank. could anyone let me know what is wrong with the below script please.

    #! /bin/sh
    # test script
    set Var1 = "Test"
    echo $Var1
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2009
    Location
    Nebraska, USA
    Posts
    829
    Rep Power
    275
    you don't need to use set.

    working example is this
    Code:
    #!/bin/sh
    #test script
    Var1="Test"
    echo $Var1
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0
    Originally Posted by DonR
    you don't need to use set.

    working example is this
    Code:
    #!/bin/sh
    #test script
    Var1="Test"
    echo $Var1
    Thanks DonR, tried using the code you advised, i get the following error

    $ ./t_script
    ./t_script: line 3: Var1: command not found
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,398
    Rep Power
    1688
    I susoect you will have spaces in the line ..

    Code:
    Var1  =   "value"
    (exaggaerated number of spaces to make it clear!)
    where it shoule not have spaces:
    Code:
    Var1="value"

    Comments on this post

    • aitken325i agrees
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0
    Originally Posted by SimonJM
    I susoect you will have spaces in the line ..

    Code:
    Var1  =   "value"
    (exaggaerated number of spaces to make it clear!)
    where it shoule not have spaces:
    Code:
    Var1="value"
    Thanks Simon1, you are correct.. i removed the spaces and it worked

    DonR - Sorry did not notice that your code excluded the blank spaces.. if i had to literally copy and paste it would have worked
    Last edited by clinton_eg; December 28th, 2012 at 05:03 AM. Reason: Added a comment to DonR

IMN logo majestic logo threadwatch logo seochat tools logo