Im pretty new to bash and want to open a second bash script on a second terminal.
but for some reason im not able to doe this.
Im using gnome-terminal and ive already set my preference to "hold terminal open"
if i just type in the terminal:
gnome-terminal --window-with-profile=shit -e "./Test.sh"
I get an error that says:
The child process exited normally with status 0 (and sometimes 2)
The test bash script is one line that says:
echo "hoi"
If anyone has the answer please let me know
Thanks in advance
The child process exited normally with status 0 is not an error message. It indicates everything went well in your script.
When hold terminal open is selected, this message will appear as a pop-up on the top of the new window when a command exits. Your output is simply too short for you to see under the pop-up message. If you add more lines to your output you should be able to see something.
Related
I may have inadvertently launched a bash script containing an infinite cycle whose exit condition may be met next century, if ever. The fact is that I launched the script, as I would do with a nohup program, with
bash [scriptname].sh &
so that (as I get it, which is most probably wrong) I can close the terminal and still keep the script running, as was my intention in developing it. The script should run calculation programmes in my absence and let me gather the results after some time.
Now I want to stop it, but nothing seems to do the trick: I killed the programmes the script had launched, I removed the input file the script was getting orders from and - last and most perfect of accomplishments - I accidentally closed the terminal trying to "exit" the script, which was still giving me error messages.
How can I check whether the script is running (as it does not appear in "top")? Is the '&' relevant? Should I just ask permission to reboot the pc, if that will work and kill everything?
Thank you.
[I put a "Hi everyone" at the beginning but the editor won't let me show it. Oh, well. It's that kind of day.]
Ok, I'll put it right here to prove my stupidity, as I wandered the internet shortly (after a long wandering before writing this post) and found that the line:
kill -9 $(pgrep -f [SCRIPTNAME].sh)
does the trick from any terminal window.
I write this answer to help anyone in the same situation, but feel free to remove the thread if unnecessary (and excuse me for disturbing).
Good you found it, here is another way if you do not use bash -c and run it in current shell not a separate shell.
# put a job in background
sleep 100 &
# save the last PID of background job
MY_PID=$!
# later
kill $MY_PID
When I start a new bash shell, if I run the command echo $? as the first thing, I get 1. How can I run bash with the "default" exit code being 0?
Context: I am running msys2 in a terminal window in VS Code. If I start msys2, and then realize I didn't need a shell now and just type exit, bash exits with 1, causing VS Code to pop up an annoying warning.
Most likely something in your profile is failing and setting the status code to 1. Since status codes are overwritten by each process that runs, it'll probably be something towards the end.
I saw >_ in bash shell icon in mac and was wondering what it will do.
I tried performing the command but I was not able to figure out what happened. My command prompt silently came again.
It should be doing something, that's why it is in the icon for terminal.
Do anyone know what it does and can it be used for something?
Running >_ will successfully run (nothing), redirected to a file named _. It's not terribly useful, but that's what it does. The most useful empty redirection I've seen is to empty the contents of a file with it:
> /var/log/app.log
which, if app.log is not open by another process, will result in /var/log/app.log being empty.
If I type in, for example:
$ notepad.exe web-dev.txt
web-dev.txt obviously opens with notepad. But if I go back into my command line, I'm unable to write any more commands until I close notepad. The command line is just black with no $.
Can I not give any more commands until I'm done with that task?
notepad.exe web-dev.txt & will run the command in the background and you can keep on working.
Use jobs to see the commands running in the background.
This documentation could be helpful: http://linuxreviews.org/beginner/jobs
I have the following code written in a script anmed test.csh to start a GUI based application in foreground in Solaris Unix. When I run the script and want to kill the GUI process using Keyboard Ctrl + C, the process is not getting terminated. If I open the GUI application directly from the terminal, I am able to kill the process using Ctrl + C. Can someone help me understand why am I not able to kill the process invoked from a script?
#! /usr/bin/csh
# some script to set env variables
# GUI Process
cast
Then I execute the script using the following command. I am not able to terminate the vcast process using Ctrl + C command.
source test.csh
If it is being launched into its own thread then the hangup request may not get to the application. You could add a signal handler to cascade the hangup request or look at the process table to see what the process id is for the app and then kill it. This could also be scripted very easily.
You should better execute the script directly, instead of sourcing it.
1) first add #!/bin/csh at the beginning of your script,
2) set it as executable :
$ chmod u+x test.csh
3) execute it directly:
$ ./test.csh
you should be able to kill it. Anyway, consider that the problem may be related to some executable code that you are running within your script. Consider to try to debug your script by copy-pasting line after line in a terminal until you reach the point where it lags.
Another possible annoying issue can be an infinite while loop. Check for this kind of error too. Maybe you have a while loop that never gets the breaking point.
Regards