Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    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:


    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 User
    Join Date
    Jun 2012
    SF Bay area
    Make sure there are no spaces between the "x" and the "=" and the "4". It could be as simple as that.

  3. #3
    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. $spacer_open
  5. #4
    Quote Originally Posted by forrest_gump View Post
    "x=4: Command Not Found".

    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.:

    > set x=4;  echo $x
    > set x = 5; echo $x
    You can also use setenv in csh/tcsh, e.g.:
    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 04: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