Re: Worth mentioning in documentation
El Mon 10 of Aug, Bob Proulx profirió estas palabras: > [...] This is why quoting as if they were external programs is > required. On the other hand [[ has always been a builtin and > therefore the shell can avoid one layer of quoting and does. That's a good point to make. Thanks for clarifying. -- Juanma Menéndez Tlf: 1118 Skype: juanma_bellon
-e does not take effects in subshell
I have a export function looking like: mybuild() { ( set -e make echo "build okay" ) } I wish to use this function this way: mybuild && do_other_stuff But whatever (success or failure) make returns "build okay" is always printed and do_other_stuff always gets executed, which is my expectation. I have found below descriptions on bash manual. -e Exit immediately if a pipeline (which may consist of a single simple command), a subshell command enclosed in parentheses, or one of the commands executed as part of a command list enclosed by braces (see SHELL GRAMMAR above) exits with a non-zero status. The shell does not exit if the command that fails is part of the command list immediately following a while or until keyword, part of the test following the if or elif reserved words, part of any command executed in a && or || list except the command following the final && or ||, any command in a pipeline but the last, or if the command's return value is being inverted with !. A trap on ERR, if set, is executed before the shell exits. This option applies to the shell environment and each subshell environment separately (see COMMAND EXECUTION ENVIRONMENT above), and may cause subshells to exit before executing all the commands in the subshell. To my understanding, the purpose of these limitations is to prevent the shell exiting if a command fails in conditional testing context such as if, elif, while, isn't it? My confusion is why the && operator disables `-e' effects in the subshell. It does not make sense to continue executing remaining commands since I wish the subshell to stop on error. Or I am wrong and the results match the original designs? BR
Assigment to GROUPS doesn't return an error code
Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-redhat-linux-gnu' -DCONF_VENDOR='redhat' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -D_GNU_SOURCE -DRECYCLES_PIDS -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fwrapv uname output: Linux oc5414668263.ibm.com 2.6.32-504.23.4.el6.x86_64 #1 SMP Fri May 29 10:16:43 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux Machine Type: x86_64-redhat-linux-gnu Bash Version: 4.3.30 Patch Level: 2 Release Status: release Description: Hi, According to man page assigment to GROUPS should return error status, this is not a case: "GROUPS An array variable containing the list of groups of which the current user is a member. Assignments to GROUPS have no effect and return an error status. If GROUPS is unset, it loses its special properties, even if it is subsequently reset." [Detailed description of the problem, suggestion, or complaint.] [aty9be02@oc5414668263:/var/tmp/bash-4.3.30]$ ./bash [aty9be02@oc5414668263:/var/tmp/bash-4.3.30]$ GROUPS=100 [aty9be02@oc5414668263:/var/tmp/bash-4.3.30]$ echo $? 0 [aty9be02@oc5414668263:/var/tmp/bash-4.3.30]$ echo $GROUPS 500 [aty9be02@oc5414668263:/var/tmp/bash-4.3.30]$ set | grep GROUPS GROUPS=([0]="500" [1]="7" [2]="10" [3]="18" [4]="487" [5]="491" [6]="498" [7]="3" [8]="501" [9]="502") Repeat-By: [Describe the sequence of events that causes the problem to occur.] Fix: [Description of how to fix the problem. If you don't know a fix for the problem, don't include this section.]
Assigment to GROUPS doesn't return an error code
Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-redhat-linux-gnu' -DCONF_VENDOR='redhat' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -D_GNU_SOURCE -DRECYCLES_PIDS -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fwrapv uname output: Linux oc5414668263.ibm.com 2.6.32-504.23.4.el6.x86_64 #1 SMP Fri May 29 10:16:43 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux Machine Type: x86_64-redhat-linux-gnu Bash Version: 4.3.30 Patch Level: 2 Release Status: release Description: Hi, According to man page assigment to GROUPS should return error status, this is not a case: "GROUPS An array variable containing the list of groups of which the current user is a member. Assignments to GROUPS have no effect and return an error status. If GROUPS is unset, it loses its special properties, even if it is subsequently reset." [Detailed description of the problem, suggestion, or complaint.] [aty9be02@oc5414668263:/var/tmp/bash-4.3.30]$ ./bash [aty9be02@oc5414668263:/var/tmp/bash-4.3.30]$ GROUPS=100 [aty9be02@oc5414668263:/var/tmp/bash-4.3.30]$ echo $? 0 [aty9be02@oc5414668263:/var/tmp/bash-4.3.30]$ echo $GROUPS 500 [aty9be02@oc5414668263:/var/tmp/bash-4.3.30]$ set | grep GROUPS GROUPS=([0]="500" [1]="7" [2]="10" [3]="18" [4]="487" [5]="491" [6]="498" [7]="3" [8]="501" [9]="502") Repeat-By: [Describe the sequence of events that causes the problem to occur.] Fix: [Description of how to fix the problem. If you don't know a fix for the problem, don't include this section.] -- Pozdrawiam, Grzegorz Bajson
Re: -e does not take effects in subshell
On Tue, Aug 11, 2015 at 11:42:29AM +, PRC wrote: > mybuild() > { > ( > set -e > make > echo "build okay" > ) > } > > mybuild && do_other_stuff http://mywiki.wooledge.org/BashFAQ/105 Since mybuild is invoked as part of a compound command, set -e is suppressed. I guess this applies not only to set -e that's invoked beforehand, but even to set -e that's set within the compound command. Stop using set -e and all of these problems simply go away. mybuild() { make && echo "build okay" } mybuild && do_other_stuff
Re: Assigment to GROUPS doesn't return an error code
On 8/11/15 5:07 AM, Grzegorz Bajson wrote: > Bash Version: 4.3.30 > Patch Level: 2 > Release Status: release > > Description: > Hi, > According to man page assigment to GROUPS should return error status, > this is not a case: > > "GROUPS An array variable containing the list of groups of which > the current user is a member. Assignments to GROUPS have no effect and > return an error > status. If GROUPS is unset, it loses its special properties, even if > it is subsequently reset." Yes, the documentation is wrong. It should simply say that assignments have no effect. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/