Find the answer to your Linux question:
Results 1 to 4 of 4
Quick question: I seem to recall (my Linux days were a long time ago) that when you are trying to set a variable - say, x - to a value ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2012
    Posts
    2

    setting variables in linux


    Quick question:
    I seem to recall (my Linux days were a long time ago) that when you are trying to set a variable - say, x - to a value - say, 4 - you simply type:

    x=4

    Shell is giving me the following error when I do that:

    "x=4: Command Not Found".

    All my research seems to indicate that simply typing "x=4" should be the right thing to do.

    Any suggestions? Where exactly have I screwed up?

  2. #2
    Linux Newbie
    Join Date
    Jun 2012
    Location
    SF Bay area
    Posts
    148
    Make sure there are no spaces between the "x" and the "=" and the "4". It could be as simple as that.

  3. #3
    Just Joined!
    Join Date
    Nov 2012
    Posts
    2
    Thank you, cnamejj, for your timely response!!!
    Thought it might have been a shell issue.
    Not sure exactly what happened. For some reason, it now works (in tcsh, I have to use "set x=4" - which, interestingly enough, wasn't working either, the last time I tried).

  4. #4
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by forrest_gump View Post
    "x=4: Command Not Found".
    Hi,

    That is definitely is a csh/tcsh error. You already noted you need to use "set" in front of it. The spaces don't matter in csh/tcsh, provided that you are consistent, e.g.:

    Code:
    > set x=4;  echo $x
    4
    > set x = 5; echo $x
    5
    You can also use setenv in csh/tcsh, e.g.:
    Code:
    setenv x 4
    although that variable will be set for all subsequent sub-shells. Using set will hold a variable only for that shell (thus good for scripts).

    btw, welcome aboard!
    Last edited by atreyu; 11-11-2012 at 03:24 AM. Reason: typo

Posting Permissions

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