Sample Header Ad - 728x90

Tilde expansion vs. variables in Bash

5 votes
1 answer
1093 views
Please, consider the following snippet:
$ export xx=foo
$ sudo bash -c 'echo $xx ~'
/root
Which is ok. We can't see xx. However, if I expose it:
$ sudo -E bash -c 'echo $xx ~'
foo /home/xropi
Though many say *~* is not alias, somehow it's part of the environment because *-E* will expose the original preventing me to defer its evaluation. Is it possible to pass my variables and evaluate ~ as /root in the sudo-ed command? I'd like to get this when running with sudo:
foo /root
Asked by xropi (93 rep)
Dec 30, 2021, 04:25 AM
Last activity: Dec 31, 2021, 01:40 AM