SO I am making a simple script that loads up two scripts and a command, but for the sake of argument, lets stay simple without to many project's specifics.
Just so you know, I am working within Raspbian environment. It is the most recent release. I am on a raspberry pi 3B+ if that matters. My pi is set to start in console so I can run this script (via alias) right away.
Moving on, We have three scripts inside of, lets say originalScript.sh:
~loop.sh
~processStart.sh
~startx (this is specific, but in case you don't know, this is the command used in raspberry pi terminal ((and probably any Linux GUI system)) that initiates the OS's GUI)
The Problem. This one command needs to end with the final startx command do the GUI will load up for processStart.sh to run. The problem is that loop.sh needs to run as well, but when it is either the first or second command, the commands following are never reached. I would make it last, but when I initiate startx, the script cuts out as the GUI loads up (thus requiring you to open a new terminal and re-initiate the original scrip with errors ((because GUI is already loaded.)))
Is there a way to make loop.sh start as a process or open in another session while startx does it's thing? I have tried
`source ~/loop.sh`
`bash ./loop.sh`
and a few others in the script, but they do the same thing; initiate the script in the same window. As expected when this happens, when the loop starts, the rest of the program doesn't happen until it ends.
If I can't start that script like that, logically would there be another way to run it simultaneously through one script?
Thanks in advance for the help!
In bash, loop.sh
can be started as a background process by appending an ampersand to the command. (ie, loop.sh &
) The command will run in background and the rest of the script will continue to run.
Note that if loop.sh
is doing anything that needs to be done before startx
, you'll have to add additional logic to the script to check that startx
is ready to run.
source loop.sh
will cause run loop.sh
in the current shell and will not return until loop.sh
exits.
bash loop.sh
will start a new bash
process and run loop.sh
. The script won't continue until that bash process exits.