[bash 3.1.5] sh -c "echo -n ok" broken
GNU bash, version 3.1.5(1)-release sh -c "echo -n ok" returns "-n ok". This breaks a lot of scripts ... startup scripts in /etc/rc.d and many packages like glibc "make check" that use "sh" instead of "bash" with "-n" option. How can I make sh -c "echo -n ok" returns "ok" instead "-n ok"? I've tried compiling with --disable-strict-posix-default but that doesn't work. Thanks, Jeff ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash
Re: [bash 3.1.5] sh -c "echo -n ok" broken
On Wed, 18 Jan 2006, Chet Ramey wrote: Somehow you've enabled the xpg_echo option, either by configuring with --enable-xpg-echo-default or running `shopt -s xpg_echo' somewhere. I suspect the former. Yes, I did "--enable-xpg-echo-default" as I need echo "ok\c" to work. The older bash-3.00.15(3) works with "--enable-xpg-echo-default". So, it is possible to have both the following working in "sh" and "bash" echo -n "ok" echo "ok\c" Thanks, Jeff. ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash
Re: Bash-3.1 Official patch 10
On Wed, 22 Feb 2006, Greg Schafer wrote: status=`echo '-'| { ${GREP} -E -e 'a\' >/dev/null 2>&1 ; echo $?; }` You're having one additional "\" ... change that to ... status=`echo '-'| { ${GREP} -E -e 'a' >/dev/null 2>&1 ; echo $?; }` or split to the next line ... status=`echo '-'| { ${GREP} -E -e 'a\ ' >/dev/null 2>&1 ; echo $?; }` or remove the "\" altogether. Thanks, Jeff. ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash
bash=~ bug or feature
With bash 3.1.17(4)-release # [[ "abcd" =~ "^a" ]]; echo $? 0 With bash 3.2.17(3)-release # [[ "abcd" =~ "^a" ]]; echo $? # is this a bug??? 1 # [[ "abcd" =~ ^a ]]; echo $? 0 Is this a bug? Thanks, Jeff. ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash
Re: bash=~ bug or feature
On Thu, 17 May 2007, Bob Proulx wrote: The behavior has been intentionally changed. Please see Bash FAQ item E14. Ok, thanks. I should have read the FAQ first. Thanks, Jeff. ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash
[PATCH] silent job monitor when 'set +m'
Chet, The man page mentioned that 'set -m' should print 'a line containing their status upon their completion' ... which should imply 'set +m' should NOT print the status. Attached is a patch to 'silent' bash so that it won't print the status when 'Monitor mode' is off (set +m). If this is not the right place to do this, please suggest an alternative to silent bash when 'kill %!' is executed. Thanks, Jeff --- bash/jobs.c.org 2009-11-06 20:26:13.0 +0800 +++ bash/jobs.c 2009-11-06 23:55:17.0 +0800 @@ -3489,8 +3489,12 @@ signal_is_trapped (termsig) == 0) { /* Don't print `0' for a line number. */ - fprintf (stderr, _("%s: line %d: "), get_name_for_error (), (line_number == 0) ? 1 : line_number); - pretty_print_job (job, JLIST_NONINTERACTIVE, stderr); + if(job_control) { + fprintf (stderr, _("%s: line %d: "), + get_name_for_error (), + (line_number == 0) ? 1 : line_number); + pretty_print_job (job, JLIST_NONINTERACTIVE, stderr); + } } else if (IS_FOREGROUND (job)) {
Re: [PATCH] silent job monitor when 'set +m'
On Sat, Nov 7, 2009 at 8:12 PM, Jan Schampera wrote: > A workaround is to diswon the monster. But yes, I also stumbled over > this once. See > http://bash-hackers.org/wiki/doku.php/snipplets/kill_bg_job_without_message > "disown"... that's new to me. Nice. At least it's an alternative to "set +m". Thanks, Jeff
Re: [PATCH] silent job monitor when 'set +m'
On Sun, Nov 8, 2009 at 5:25 AM, Chet Ramey wrote: > > Are you saying you ran a script in which you enabled job > control, ran a job, turned job control off, then killed the job? > No, I didn't turn off job control. I use "set +m" to turn of monitoring only because I don't want to see any message about the job being terminated. > Bash and historical versions of sh report the status of jobs in a script > that exit as the result of being killed by a signal. I'm not going to > change that. > Isn't that the purpose of "set +m" ... to turn off monitoring? Thanks, Jeff
Re: [PATCH] silent job monitor when 'set +m'
On Sun, Nov 8, 2009 at 10:14 AM, Chet Ramey wrote: > I think you're confused about the distinction. set -m and +m turn job > control on and off. The `monitor' name is historical (ask Dave Korn > why he chose it). > That's what confused the whole issue. > What version of bash are you using? 4.0.35(12)-release Assuming you mean an interactive shell, bash-4.0 behaves like I think you > want: > > $ sleep 40 & > [1] 19038 > $ set +m > $ kill %1 > $ fg %1 > bash: fg: no job control > $ set -m > $ sleep 40 & > [1] 19041 > $ kill %1 > $ > [1]+ Terminated sleep 40 > $ > That's exactly what I wanted. Thanks for the detailed sample! Sorry for the confusion. Please ignore the patch. Bash as it is. Jeff
Re: [PATCH] silent job monitor when 'set +m'
> On Sun, Nov 8, 2009 at 5:25 AM, Chet Ramey wrote: > non-interactive shells don't have job control enabled by default. Are you saying > you ran a script in which you enabled job control, ran a job, turned job control off, > then killed the job? > Bash and historical versions of sh report the status of jobs in a script > that exit as the result of being killed by a signal. I'm not going to > change that. Chet, Revisited. The previous reply to your example works fine for interactive shell. But for a script (non-interactive shell), the example does not work the same. Job status are always reported even with "set +m" in the script. ... Running the examples you gave in a "script" slightly enhanced to use "ps" to show the processes with the following script. $ cat /tmp/a1 #!/bin/bash sleep 60 & P=$! /bin/ps Tfo "pid ppid command" set -m echo "\$-="$- kill $P /bin/ps Tfo "pid ppid command" sleep 60 & P=$! /bin/ps Tfo "pid ppid command" set +m echo "\$-="$- kill $P /bin/ps Tfo "pid ppid command" 1) Case 1. Without patch. $ /tmp/a1 PID PPID COMMAND 25048 25047 -bash 25774 25048 \_ /bin/bash /tmp/a1 25775 25774 \_ sleep 60 25776 25774 \_ /bin/ps Tfo pid ppid command $-=hmB PID PPID COMMAND 25048 25047 -bash 25774 25048 \_ /bin/bash /tmp/a1 25777 25774 \_ /bin/ps Tfo pid ppid command /tmp/a1: line 8: 25775 Terminated sleep 60 PID PPID COMMAND 25048 25047 -bash 25774 25048 \_ /bin/bash /tmp/a1 25778 25774 \_ sleep 60 25779 25774 \_ /bin/ps Tfo pid ppid command $-=hB PID PPID COMMAND 25048 25047 -bash 25774 25048 \_ /bin/bash /tmp/a1 25780 25774 \_ /bin/ps Tfo pid ppid command /tmp/a1: line 16: 25778 Terminated sleep 60 2) Case 2. With patch applied. "set +m" no longer reports job killed. $ /tmp/a1 PID PPID COMMAND 25048 25047 -bash 26242 25048 \_ /bin/bash /tmp/a1 26243 26242 \_ sleep 60 26244 26242 \_ /bin/ps Tfo pid ppid command $-=hmB PID PPID COMMAND 25048 25047 -bash 26242 25048 \_ /bin/bash /tmp/a1 26245 26242 \_ /bin/ps Tfo pid ppid command /tmp/a1: line 8: 26243 Terminated sleep 60 PID PPID COMMAND 25048 25047 -bash 26242 25048 \_ /bin/bash /tmp/a1 26246 26242 \_ sleep 60 26247 26242 \_ /bin/ps Tfo pid ppid command $-=hB PID PPID COMMAND 25048 25047 -bash 26242 25048 \_ /bin/bash /tmp/a1 26248 26242 \_ /bin/ps Tfo pid ppid command Is there another alternative to do this? "disown" would not work for situation where "wait" is used to wait for child to finish ... sleep 80 & P=$! disown $P # this would not work for 'wait' command next (sleep 2; kill $P) & wait $P Thanks, Jeff
Re: [PATCH] silent job monitor when 'set +m'
On Mon, Nov 9, 2009 at 10:42 AM, Chet Ramey wrote: > Sure. Since the status messages are written to stderr, you can save > file descriptor 2 and temporarily (or permanently, depending on your > needs) redirect it to /dev/null. > That means another subshell. Thanks for all your help. Jeff.
Re: [PATCH] silent job monitor when 'set +m'
On Tue, Nov 10, 2009 at 6:20 AM, Jan Schampera wrote: > Chet Ramey schrieb: > > > redirect stderr > > kill pid > > wait pid > > restore stderr > > > > It seems to me that this sequence forces the necessary synchronicity. > > Interesting. And sad that I never thought of that > Will you consider having like a new option "set -j" to switch displaying job information on/off"? Jeff
Re: [PATCH] silent job monitor when 'set +m'
On Tue, Nov 10, 2009 at 11:09 PM, Chet Ramey wrote: > Jeff Chua wrote: > > > > > > On Tue, Nov 10, 2009 at 6:20 AM, Jan Schampera > <mailto:jan.schamp...@web.de>> wrote: > > > > Chet Ramey schrieb: > > > > > redirect stderr > > > kill pid > > > wait pid > > > restore stderr > > > > > > It seems to me that this sequence forces the necessary > synchronicity. > > > > Interesting. And sad that I never thought of that > > > > > > Will you consider having like a new option "set -j" to switch displaying > > job information on/off"? > > I am inclined not, since there's a relatively easy workaround. > How do you silent this one without a subshell. I just don't want to see the "Terminated" output, but everything else in case there's error. #!/bin/bash sleep 60 & P=$! kill $P sleep 1 exit Currently, I'm doing it this way ... #!/bin/bash ( sleep 60 & P=$! kill $P sleep 1 ) 2>&1 | grep -v " Terminated" exit Thanks, Jeff
Re: [PATCH] silent job monitor when 'set +m'
On Wed, Nov 11, 2009 at 12:44 AM, Chet Ramey wrote: > > How do you silent this one without a subshell. > > What's wrong with the approach above? > Nothing wrong, but can be made more efficient because "| grep" means another subprocess which can be eliminated if the shell silents the Terminate command in the first place. #!/bin/bash { sleep 60 & P=$! kill $P sleep 1 } 2>&1 | grep -v " Terminated" exit Jeff
Re: [PATCH] silent job monitor when 'set +m'
On Wed, Nov 11, 2009 at 12:04 PM, Jeff Chua wrote: > > > On Wed, Nov 11, 2009 at 12:44 AM, Chet Ramey wrote: > >> > How do you silent this one without a subshell. >> >> What's wrong with the approach above? >> > > Nothing wrong, but can be made more efficient because "| grep" means > another subprocess which can be eliminated if the shell silents the > Terminate command in the first place. > > #!/bin/bash > { > sleep 60 & > P=$! > kill $P > sleep 1 > } 2>&1 | grep -v " Terminated" > exit > Extending the example above slighting ... now with grep means I can't see the message real-time anymore ... if you try the example below without the grep, it should display 0 1 2 ... every second. #!/bin/bash { for((i = 0; i <100; i++)) do echo " $i\c" sleep 1 done & P=$! sleep 10 kill $P sleep 1 echo ok } 2>&1 | grep -v " Terminated" exit Thanks, Jeff