Why doesn\'t the following work?
$ alias sayHello=\'/bin/echo \"Hello world!\"\'
$ sayHello
Hello world!
$ nohup sayHello
nohup: appending output to `n
With bash, you can invoke a subshell interactively using the -i
option. This will source your .bashrc
as well as enable the expand_aliases
shell option. Granted, this will only work if your alias is defined in your .bashrc
which is the convention.
Bash manpage:
If the
-i
option is present, the shell is interactive.expand_aliases: If set, aliases are expanded as described above under ALIASES. This option is enabled by default for interactive shells.
When an interactive shell that is not a login shell is started, bash reads and executes commands from
/etc/bash.bashrc
and~/.bashrc
, if these files exist.
$ nohup bash -ci 'sayHello'