Using aliases with nohup

后端 未结 4 1574

Why doesn\'t the following work?

$ alias sayHello=\'/bin/echo \"Hello world!\"\'
$ sayHello 
    Hello world!
$ nohup sayHello
    nohup: appending output to `n         


        
4条回答
  •  攒了一身酷
    2021-02-19 12:26

    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'
    

提交回复
热议问题