Thanks for the reply. With your input I further get the following information,
job control is by default turned off in non-interactive mode (shell script runs in non-interactive mode -- Bash Reference Manual). So to enable job control, we need set -m explicitly.
It seems that I am not the only one feel confused about this statement , in a discussion in stackoverflow, Why can't I use job control in a bash script? - Stack Overflow, someone else asked "So why doesn't script-based job-control work, and what makes it a bad practice (aka 'stupid')?". Although there some answers for it, I still feel this controlling-terminal-job-control-foreground-background thing not so easy to get.
Initializing the Shell - The GNU C Library -- "A subshell that runs non-interactively cannot and should not support job control. ... this allows the non-interactive shell and its child processes to be treated as a single job by the parent shell." Even harder to get
I happened to see this thread while searching for a solution to an odd bash scripting problem. It seems that there is in fact a use for job control in a shell script, though it may simply be a workabout for an existing bug.
Here I have a simple two line script "test.sh", it runs mplayer in the background and waits for an "Enter". (My actual use is for a sshfs wrapper, but the example uses mplayer as it is more widely available)
If I were to run xterm, manually run the script with "./test.sh", then close xterm, everything works as expected. mplayer continues to run in the background.
But if I were to run this script via "xterm -e ./test.sh". mplayer runs as expected, but when "Enter" is pressed, the script end, xterm closes, and mplayers dies. The same happens if I were to use gnome-terminal. Doing a "ps -axf" after mplayer starts, but before hitting "Enter", I see that mplayer is still in the foreground process group.
By modifying the script to the following, things works as expected again.
I have no idea why this is so, but it would seem that others have encountered similar problems (but without solutions):
Anyone knows if this is a bug in bash / xterm? My guess is that when running without job control, the & don't actually cause the process to be removed from the foreground process group immediately, but only after the end of the script. Somehow, this step was missed when running the script via "xterm -e". This is just my speculation, so hopefully someone more knowledgeable can shed some light on the matter.
Hi Folks -
Is there a way to add two execs to one script? For instance, I need to redirect the stdout and stderr to two separate directories. I want to do this:
#::-- Direct STDOUT and STDERROR to repositories --::#
exec 2>"${_ERRORFILE}" > "${_LOGFILE}"
exec 2>"/new/path/file.err" >... (7 Replies)
hi,
trying to embed an image to the html file to send out as an email.
img src="data:image/jpeg;base64,$(base64 /home/test/abc.jpg
but getting error as file not found after it aplies base64 on the file. (8 Replies)
Hi I would like to embed a sql query in my shell script.
Also, before any the sql query is executed, i would like to validate username and password. (1 Reply)
Hello everyone,
I am trying to embed some tcl code inside a ksh93 script but I am not having any success.
I even tried the simplest of code, something like this:
.
.
jk=$(echo $(tcl << |
write_file junkme "test"'
|
))
just to see if a file gets written. When I run there are no errors, but ... (3 Replies)
Hello;
When I try:
awk '/$(date "+%y\/%m\/%d")/,0'
It errors with:
awk: There is a regular expression error.
Invalid pattern.
Is there anyway to make this work ??
Thank you (2 Replies)
Hi
Can I thank the advice I've received on here previously, working examples are helping me teach myself BASH fairly quickly and I've written some pretty complex scripts now (even if I do say so myself).
Anyhooo.....
I'm writing a script that handles lots of text files and does various... (3 Replies)
Can anyone help me out in visualizing on what is the logic behind simple unix commands. For Eg: ls command lists files and directories, how it displays I need to know the source code for commands like this. (1 Reply)
Hi friends this is first post i am very new to shell scripting so i require your expertise to do the following thank u
I need to write a shell script which will run the following commands
pg_dump bank > backup(Enter)
Wait for bash prompt to appear coz it indicates that the command is... (23 Replies)
I have written a code to extract comma seperated values from a file and assign them to a variable inside awk code.i want to use one of these variable to be used in wget function i.e to pass the siteurl.How i can implement the shell command wget inside the awk for loop.code snippet is shown below. ... (8 Replies)
Hi ,
I am having one situation in which I need to run some simple unix commands after doing "chroot" command in a shell script. Which in turn creates a new shell.
So scenario is that
- I need to have one shell script which is ran as a part of crontab
- in this shell script I need to do a... (2 Replies)