linux bash: when opening xterm with -e, the varaibles are not getting defined

376 Views Asked by At

I am trying a simple xterm command:

xterm -hold -e "hare=0;echo $hare"

it will open xterm with blank

What i observed is variable hare is not getting defined inside the -e quotes

where as:

hare=0;xterm -hold -e "echo $hare"

it opens an xterm showing 0

i have to define variables in the -e quotes and do something. Is it possible or not. I want xterm to access the outside variables and also the variables defined in the -e

1

There are 1 best solutions below

8
On BEST ANSWER

Variables are expanded inside double-quoted strings, so the variable is being expanded by the original shell, not the shell in the xterm. Use single quotes.

xterm -hold -e 'hare=0; echo $hare'

If you assign the variable in the original shell, you need to export it so it will become an environment variable that's inherited by child processes:

hare=0
export hare
xterm -e 'echo $hare'