Making $! and $? searchable in the man page
Hi, Finding the meaning of $? and $! in the man page is quite hard for people not familiar with the layout and bash terminology (this frequently comes up in Freenode #bash). It would be very helpful for them if you could simply search for "$!" to find the description of the parameter !. Below is a suggestion patch that just adds a $ in front of the parameters under Special Parameters to make this possible. PS: I'm not on the list. Vidar diff -rup bash-4.1/doc/bash.1 bash-4.1-new/doc/bash.1 --- bash-4.1/doc/bash.1 2009-12-30 19:01:31.0 +0100 +++ bash-4.1-new/doc/bash.1 2011-01-06 10:19:06.0 +0100 @@ -1231,7 +1231,7 @@ The shell treats several parameters spec only be referenced; assignment to them is not allowed. .PD 0 .TP -.B * +.B $* Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, it expands to a single word with the value of each parameter separated by the first character @@ -1253,7 +1253,7 @@ If .B IFS is null, the parameters are joined without intervening separators. .TP -.B @ +.B $@ Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each parameter expands to a separate word. That is, "\...@\fp" is equivalent to @@ -1266,14 +1266,14 @@ When there are no positional parameters, .B $@ expand to nothing (i.e., they are removed). .TP -.B # +.B $# Expands to the number of positional parameters in decimal. .TP -.B ? +.B $? Expands to the exit status of the most recently executed foreground pipeline. .TP -.B \- +.B $\- Expands to the current option flags as specified upon invocation, by the .B set @@ -1282,16 +1282,16 @@ builtin command, or those set by the she .B \-i option). .TP -.B $ +.B $$ Expands to the process ID of the shell. In a () subshell, it expands to the process ID of the current shell, not the subshell. .TP -.B ! +.B $! Expands to the process ID of the most recently executed background (asynchronous) command. .TP -.B 0 +.B $0 Expands to the name of the shell or shell script. This is set at shell initialization. If .B bash @@ -1309,7 +1309,7 @@ to the file name used to invoke .BR bash , as given by argument zero. .TP -.B _ +.B $_ At shell startup, set to the absolute pathname used to invoke the shell or shell script being executed as passed in the environment or argument list.
Re: Making $! and $? searchable in the man page
On Thu, Jan 06, 2011 at 10:48:33AM +0100, Vidar Holen wrote: > Hi, > > Finding the meaning of $? and $! in the man page is quite hard for people > not familiar with the layout and bash terminology (this frequently comes > up in Freenode #bash). It would be very helpful for them if you could > simply search for "$!" to find the description of the parameter !. I absolutely second this. In fact, I sent a very similar patch for this last year.
Re: read builtin and readonly variables
On 01/04/2011 08:05 AM, Eric Blake wrote: > I couldn't find anything either - the POSIX wording for readonly only > mentions assignment and unset as requiring errors. I think that's an > unintentional hole in POSIX, though, so I'm going ahead and submitting a > bug report to have readonly also mention read and getopts as being > required to error out on a readonly variable (and given that ksh treats > assignment different than unset on whether a non-interactive shell > exits, the extent of the reaction for getopts and read will probably > have to allow both behaviors). I found some other differences between shells: $ bash --posix -c 'cd /tmp; readonly PWD; echo $?; cd ..; echo $?-$PWD-$(pwd)' || echo abort,$? 0 bash: PWD: readonly variable 0-/tmp-/ $ bash -c 'cd /tmp; readonly PWD; echo $?; cd ..; echo $?-$PWD-$(pwd)' || echo abort,$? 0 bash: PWD: readonly variable 0-/tmp-/ $ ksh -c 'cd /tmp; readonly PWD; echo $?; cd ..; echo $?-$PWD-$(pwd)' || echo abort,$? 0 0-/-/ Bash goes ahead and changes the directory but leaves PWD untouched (PWD is now inconsistent without warning!) in both posix and bash mode, whereas ksh (silently) ignores the request to make PWD readonly in the first place. Also, both shells abort a non-interactive shell when readonly interferes with export (but bash only aborts in posix mode): $ ksh -c 'readonly v; export v=a; echo $?-$a' || echo abort,$? ksh: line 1: v: is read only abort,1 $ bash -c 'readonly v; export v=a; echo $?-$a' || echo abort,$? bash: v: readonly variable 1- $ bash --posix -c 'readonly v; export v=a; echo $?-$a' || echo abort,$? bash: v: readonly variable abort,1 I've gone ahead and filed a POSIX interpretation request: http://austingroupbugs.net/view.php?id=367 Also, since the next version of POSIX will be mandating changes for cd (http://austingroupbugs.net/view.php?id=253 adds the new cd -e option to warn if PWD is inconsistent), the notion of a readonly PWD may affect how you implement that proposal. -- Eric Blake ebl...@redhat.com+1-801-349-2682 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
for; do; done regression ?
Hi! I ran the command ~$ time for i in `seq 0 1` ; do echo /o/23/4 | cut -d'/' -f2 ; done > /dev/null 6 times in a row, and noticed to the increase in execution time: 1) real0m16.573s user0m0.390s sys 0m4.240s 2) real0m19.883s user0m0.330s sys 0m4.290s 3) real0m25.827s user0m0.480s sys 0m4.490s 4) real0m31.566s user0m0.440s sys 0m4.810s 5) real0m37.981s user0m0.770s sys 0m4.860s 6) real0m42.545s user0m1.560s sys 0m4.850s how to interpret the results? GNU bash, version 4.1.7(2)-release (x86_64-pc-linux-gnu)
Re: Making $! and $? searchable in the man page
On Fri, Jan 7, 2011 at 1:33 AM, Greg Wooledge wrote: > On Thu, Jan 06, 2011 at 10:48:33AM +0100, Vidar Holen wrote: > > Hi, > > > > Finding the meaning of $? and $! in the man page is quite hard for people > > not familiar with the layout and bash terminology (this frequently comes > > up in Freenode #bash). It would be very helpful for them if you could > > simply search for "$!" to find the description of the parameter !. > > I absolutely second this. In fact, I sent a very similar patch for this > last year. > > Agree. Also for this: ${parameter} The value of parameter is substituted. The braces are required when parameter is a positional parameter with more than one digit, or when parameter is followed by a character which is not to be interpreted as part of its name. If the first character of parameter is an exclamation point, a level of variable indirection is introduced. I recommend to add another line just after ${parameter}: ${parameter} ${!parameter} -- Clark