We help IT Professionals succeed at work.

UNIX errors?

brianjava
brianjava asked
on
I am getting an error for following :

$FIRST-NAME=tom
ksh: FIRST-NAME=tom: not found

??
Comment
Watch Question

Commented:
What are you doing that raises these errors?

Author

Commented:
simple search...
Do not use "-" and variable name use "_" instead
If you want to set the variable, you type in:
you can do"
FIRST_NAME=tom
echo $FIRST_NAME
or
FIRSTNAME=tom
echo $FIRSTNAME
PS: In *nix, you should avoid use WHITE space, and Special Characters for filename, variable names.
http://docstore.mik.ua/orelly/unix/upt/ch08_19.htm 
Kerem ERSOYPresident
Commented:
Hi,

When you want to assign a value to a variable use its name directly suche as:

FIRST_NAME=Tom

not as

$FIRST_NAME=Tom

$variable_name simply refers the value of the variable not the variable itself. So obviously it is not possible to assign a value to the value of a variable.

Cheers,
K.


Author

Commented:
if I use FIRST_NAME=Tom

do I still need to use echo $ command??
Top Expert 2007

Commented:
In Unix/Linux you assign a variable like

var="some value"

and whenever you want to refer to that variable, you use $var, eg:

echo $var

Kerem ERSOYPresident

Commented:
When assigning value you are refreing the varable itself
with echo you are refering the value tit contains.

So in the first case you don't need "$"
but for the second case you definitely need "$"

echo FIRST_NAME

will print only:

FIRST_NAME

becasue echo will not understand you're refering the value FIRST_NAME and print it as ordinary text. While

echo $FIRST_NAME
will print:

Tom


Because $ will tell echo that the following expression is a variable name. Echo will print the contents of the variable.

Cheers,
K:


HI brianjava,
My comments worth nothing? You should be fair to all experts.

Author

Commented:
yuzh....

I gave the points to the wrong person.....my mistake.

can I reopen the points somehow???
hi brianjava,
thank you for correction.
yuzh