linux - exporting variables which are variable values in shell -


when try this...

$ export my_path='/my/path\ with\ spaces/file' $ echo $my_path` /my/path\ with\ spaces/file 

it works.

but want this..

$ echo $my_variable my_path='/my/path\ with\ spaces/file' $ export $my_variable -bash: export: `with\': not valid identifier -bash: export: `spaces/file'': not valid identifier 

this error iam getting. there way treat value of variable exporting.. [[ note: if path did not have space, works perfectly!! ]]

don't use $. otherwise shell expand variable's value before passing export. following work:

export my_variable 

in comments, points out wan't store variable assignment variable , pass export. here comes example:

var='foo=bar' export "$var"  # check if succeeded  export | grep foo # output: declare -x foo="bar" 

Comments