Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Linux by (18.4k points)

How do I print an environment variable just being set?

NAME=sam echo "$NAME" # empty

I found that eval works. Is it the correct way?

NAME=sam eval 'echo $NAME' # => sam

1 Answer

0 votes
by (36.8k points)

These need to go since different commands e.g.:

NAME=sam; echo "$NAME"

NAME=sam && echo "$NAME"

The extension $NAME to empty string is done by using the shell earlier, before running the echo, Both the NAME variable is passed to this echo command's environment, the expansion is already done (to null string).

To get same result, in 1 command:

NAME=sam printenv NAME

 Come and join Linux training to gain great knowledge. 

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...