-1

When I get around to making my internet radio (still waiting for parts), I will want the command line available to startx the GUI to edit the playlist (or whatever) while the radio continues playing headless (X will otherwise not be running since it won't be needed in normal operation). My initial thought was to launch a new shell from the player but then I realized I should be able to run the radio script instead in its own shell process while letting the startup finish anything else I might have it do.

I was thinking I might use:

bash radio.py

in the startup but then I found:

radio.py &

should do the same thing.

Is there a difference between the two beyond the number of characters typed on the line?

  • The main difference is that bash radio.py should not even work, unless you disguise your shell scripts as Python files. – Dmitry Grigoryev Feb 7 '17 at 14:00
2

tl;dr Preceding the file name with bash will cause it to be interpreted by bash. The & at the end will cause the program to be executed in the background. These "directives" are not mutually exclusive.

But there are more differences between the two commands you ask about:

  • When you execute:

    radio.py &
    
    1. The system will first look for a shebang and run the radio.py using the command defined in the string (most likely Python).

    2. The & will put the running program in the background.

      You can then bring the process to the foreground using the following command:

      fg
      
    3. The command requires radio.py script to be saved in one of the directories specified in the PATH environment variable.

    4. It requires radio.py file to have executable permission set for the user you are running the command as.

  • When you execute:

    bash radio.py
    
    1. You are telling bash to interpret the given script (radio.py).

      In your case (judging from the file extension) it will cause a syntax error, because bash does not interpret Python code (and shebang will not be taken into account).

    2. The lack of & will cause bash to run like in foreground (which is how most commands in the shell are run).

    3. The command requires radio.py script to be saved in the current directory.

    4. Unlike executing the file directly, providing its name as the argument does not require setting execute permissions.

| improve this answer | |
0

radio.py & will leave the process running in the background until it completes. You will have little access to it, except to kill.

Use bash if you want to start another console session.

NOTE whatever you do you need to specify FULL PATHS to all files.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.