My operating system is Ubuntu Linux 18.04 (Xubuntu) and bash version 4.4.19
By entering the following shell commands:
bash -c 'foo="echo bar" && $foo'
bash -c 'alias foo="echo bar" && foo'
alias foo="echo bar" && foo
I get the following output:
bar
(expected)bash: foo: command not found
(a simplebar
was expected)bar
(expected)
The reason I ask is because I have a complicated script, which uses aliases, that I would like to execute as root
.
I have tried:
sudo bash -c '/path/to/script.sh'
But the script fails when using its own aliases. Unfortunately, switching to root (sudo -i
) isn't an option in my desired case scenario.