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.
- 11-09-2012 #1Just 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?
- 11-09-2012 #2Linux Newbie
- Join Date
- Jun 2012
- Location
- SF Bay area
- Posts
- 101
Make sure there are no spaces between the "x" and the "=" and the "4". It could be as simple as that.
- 11-09-2012 #3Just 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).
- 11-11-2012 #4Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,700
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.:
You can also use setenv in csh/tcsh, e.g.:Code:> set x=4; echo $x 4 > set x = 5; echo $x 5
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).Code:setenv x 4
btw, welcome aboard!Last edited by atreyu; 11-11-2012 at 03:24 AM. Reason: typo


Reply With Quote

