Using aliases with nohup

后端 未结 4 1573

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:20

    Because the shell doesn't pass aliases on to child processes (except when you use $() or ``).

    $ alias sayHello='/bin/echo "Hello world!"'

    Now an alias is known in this shell process, which is fine but only works in this one shell process.

    $ sayHello 
    
    Hello world!
    

    Since you said "sayHello" in the same shell it worked.

    $ nohup sayHello
    

    Here, a program "nohup" is being started as a child process. Therefore, it will not receive the aliases. Then it starts the child process "sayHello" - which isn't found.

    For your specific problem, it's best to make the new "perl" and "python" look like the normal ones as much as possible. I'd suggest to set the search path.

    In your ~/.bash_profile add

    export PATH="/my/shiny/interpreters/bin:${PATH}"
    

    Then re-login.

    Since this is an environment variable, it will be passed to all the child processes, be they shells or not - it should now work very often.

提交回复
热议问题