Not able to read variable in unix

Discussion in 'Mac Programming' started by neowin, Oct 3, 2011.

  1. neowin macrumors newbie

    Joined:
    Jun 27, 2011
    #1
    Hi,

    I am trying to display a variable's value in terminal of mac. But it is not happening.

    This is the steps I do-

    set var = 2
    echo $var

    This should display 2, but a empty line is shown.
    I think I need to set some env variable.But i do not know the details. Please help.
     
  2. ChrisA macrumors G4

    Joined:
    Jan 5, 2006
    Location:
    Redondo Beach, California
    #2
    Which shell is this?

    If it is "bash"

    then try this
    var=2
    echo $var.

    If you are running "csh" then it would be
    setenv var 2
    echo $var

    You title says "in UNIX" yes Mac OS is based on UNIX but UNIX is the name of an OS.. What you are typing commands into is a program called a shell. There are several shells you can use. Mac OS X ships with at least three shells and you get to pick with runs for each account
     
  3. neowin thread starter macrumors newbie

    Joined:
    Jun 27, 2011
    #3
    Yep got it. Thanks!

    instead of
    set var = 2
    i did
    var=2

    This prints the value.
     

Share This Page