PDA

View Full Version : echo $123 outputs 23



adit
August 23rd, 2010, 04:15 PM
I didn't define any environment variable 123. When I type echo $123 in the terminal I get the output 23. How?

GeneralZod
August 23rd, 2010, 04:20 PM
I didn't define any environment variable 123. When I type echo $123 in the terminal I get the output 23. How?

Presumably, "$123" is parsed as


$1 followed by the string


23

surfer
August 23rd, 2010, 04:22 PM
#!/bin/bash
echo $123


if you save that in a shell script and call is test.sh



$ ./test.sh hello

will give you hello23.

bash variables must not start with numbers! $1 is the first argument you pass on the command line.