Using aliases with nohup

Why does the following not work?

$ alias sayHello='/bin/echo "Hello world!"' $ sayHello Hello world! $ nohup sayHello nohup: appending output to `nohup.out' nohup: cannot run command `sayHello': No such file or directory 

(the reason I ask this question is because I pointed perl and python aliases to different perl / python executables that were optimized for my own purposes, however nohup gives me problems if I don't offer the full path to to my perl / python binaries)

+6
source share
4 answers

Because the shell does not pass aliases to child processes (unless you use $ () or ``).

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

Now in this shell process, an alias is known that works fine, but only works in this single-class process.

 $ sayHello Hello world! 

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

 $ nohup sayHello 

Here, the nohup program starts as a child process. Therefore, he will not receive pseudonyms. Then it starts the child process "sayHello" - which is not found.

For your specific problem, it is best to use the new "perl" and "python" as common as possible. I would suggest setting a search path.

In your ~ / .bash_profile add: export PATH = "/ my / shiny / interpers / bin: $ {PATH}"

Then go.

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

+7
source

For bash: try making nohup ' your_alias '. It works for me. I do not know why the reverse quote is not shown. Put your alias in quotation marks.

+2
source

With bash, you can interactively attach a subtitle using the -i option. This will lead to the source of your .bashrc and also enable the expand_aliases shell expand_aliases . Of course, 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 expand as described above in the ALIASES section. This option is enabled by default for interactive skins.

When an interactive shell that is not a login shell is launched, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc , if these files exist.


 $ nohup bash -ci 'sayHello' 
+1
source

If you look at the Aliases section of the Bash manual, it says

The first word of each simple command, if not specified, is checked to see if it has an alias.

Unfortunately, it seems that bash has something like zsh global aliases that expand at any position.

0
source

Source: https://habr.com/ru/post/908557/


All Articles