Re: Exit-on-error option does not work as expected
On 7/17/07, Paul Jarc <[EMAIL PROTECTED]> wrote: Nevertheless, it is. The current behavior is too well-entrenched to change it, so the most reliable way to get the behavior you want is to skip "-e" and add "&&" between all commands. Change the documentation to insert the bracketed sentence: ... is being inverted using `!'. [If the failing command is inside braces, parenthesis, or in a function, the "unless" conditions above apply also to the grouping as a whole.] A trap on `ERR' ... ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash
Re: Subnet address
On 7/20/07, Mike Frysinger <[EMAIL PROTECTED]> did not read the question. The answer is: /sbin/ifconfig eth0 | grep 'inet addr' | tr .: ' ' | (read inet addr a b c d Bcast e f g h Mask i j k l; echo $(($a & $i)).$(($b & $j )).$(( $c & $k )).$(( $d & $l )) ) ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash
Re: TZ=... date affected PROMPT_COMMAND
This version works the same as the more verbose one: PROMPT_COMMAND='prompt_status=\ $?' PS1=$SPECIAL_PS1"$my_color_on\A\${prompt_status# 0} \W\$$my_color_off " Putting the variables inside $(...) avoids global variables and use of PROMPT_COMMAND: PS1='\A$(S=$?; W=$((S>99?4:(S>9?3:(S>0?2:0; printf "%*.d " $W $S)\W\$' PS1=$SPECIAL_PS1"$my_color_on$PS1$my_color_off " This works even if PROMPT_COMMAND is set, since PROMPT_COMMAND is not "the most recently executed foreground pipeline," and does not change the value of $?. I claim this is a bash bug: gcc is perfectly happy with S>99?4:S>9?3:S>0?2:0, but GNU bash, version 3.2.33(1)-release (i386-redhat-linux-gnu) chokes on W=$((S>99?4:S>9?3:S>0?2:0)). The bash man page promises that "The operators and their precedence, associativity, and values are the same as in the C language."
bash: S>99?4:S>9?3:S>0?2:0: syntax error in expression
Configuration Information [Automatically generated, do not change]: Machine: i386 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i386' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i386-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 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables uname output: Linux beta.localnet 2.6.25-0.121.rc5.git4.fc9 #1 SMP Fri Mar 14 23:14:20 EDT 2008 i686 i686 i386 GNU/Linux Machine Type: i386-redhat-linux-gnu Bash Version: 3.2 Patch Level: 33 Release Status: release Description: gcc accepts the expression S>99?4:S>9?3:S>0?2:0 bash 3.2(33) does not. I claim this is a bash bug: gcc is perfectly happy with S>99?4:S>9?3:S>0?2:0, but GNU bash, version 3.2.33(1)-release (i386-redhat-linux-gnu) chokes on W=$((S>99?4:S>9?3:S>0?2:0)). The bash man page promises that "The operators and their precedence, associativity, and values are the same as in the C language."
Re: -e does not work inside subscript when using || or && operator outside
On Wed, Aug 6, 2008 at 7:13 AM, Christian Jaeger <[EMAIL PROTECTED]> wrote: >$ bash -c '( set -e ; false; echo "hu?" ) || echo "false"' >hu? ># expecting "false" > >$ bash -c '( set -e ; false; echo "hu?" ); if [ $? -ne 0 ]; then echo > "false"; fi' >false > ># Also: >$ bash -c '( set -e ; false; echo "hu?" ) && echo "false"' >hu? >false ># expecting no output On Wed, Aug 6, 2008 at 10:42 AM, Christian Jaeger <[EMAIL PROTECTED]> wrote: > http://www.opengroup.org/onlinepubs/009695399/utilities/set.html This is bad documentation and ambiguous standardization. The linked opengroup standard includes the wording > When this option is on, if a simple command [fails or exits with status >0], > and is not ... and is not ... and is not ..., then the shell shall > immediately exit. What is not specified is whether the scope of the "and is not" conditions extends outside the subshell created by a fork or not. Does the meaning of a script enclosed in parenthesis depend on what appears outside parenthesis? The behavior of bash clearly shows the answer is "yes", at least in this case. Is this documented? Thus, in the above definition for set -e, assume the simple command ("false" in the example) meets all of the "and is not" conditions" locally within the parenthesis. Then if the parenthesis enclosed fragment taken as a simple command also meets all of the "and is not" conditions, then "the shell shall immediately exit" means "the subshell shall immediately exit and the shell shall not exit". That is, the child process shall exit and the parent process shall resume execution at the close parenthesis. Thus, "exit" is taken relative to the subshell, but the conditions are taken relative to the whole script. Otherwise, "the shell shall immediately exit" actually means "the subshell shall not exit." That is, the child process, upon finding that the simple command has failed, looks in the forked memory image at the state inherited from all its ancestors and notes that one of them has registered a failure handler, and therefore decides to ignore the failure without even looking at the set -e flag. The semantics of "set -e; false; echo unreachable" depends on the state of the interpreter when the script fragment is executed, and cannot be determined without reference to inherited state. This also applies when the fragment appears within a function: the semantics varies from call to call. I think the standard needs to refer to the state of the interpreter in defining the semantics of set -e, rather than pretending that the meaning is context free.
Re: Last modified files with owner / time / permissions
On Wed, Sep 10, 2008 at 3:11 PM, lexton <[EMAIL PROTECTED]> wrote: > ... bash script that prints out the files that have been modified in > the last 5 days ... Try this: #!/bin/bash # note run above line with -x for debug mode export PATH=/usr/bin:/bin FILENAMECOLUMN=8 # 9 on old systems or if LC_TIME=posix. WEBSITES=/websites/path { # disk space left df -h printf "\n\n" # last logins to system last # last 5 days of file modications sorted by the file path. printf "\n Last 5 Days (all depths) \n" find "$WEBSITES" -daystart -type f -mtime -5 -print0 | xargs -0 --no-run-if-empty ls -l | sort -k $FILENAMECOLUMN # all level 1 files sorted by modification time printf "\n Full List \n" ls -lt "$WEBSITES"/* } | mail -s 'dev info' [EMAIL PROTECTED]
Re: Strange change between bash-3.2 and bash-4.0
Ulrich Drepper in comment 6 to redhat bug 483385 links to austin-group-l, item 11863 by Geoff Clare: https://bugzilla.redhat.com/show_bug.cgi?id=483385#c6 https://www.opengroup.org/sophocles/show_mail.tpl?CALLER=index.tpl&source=L&listname=austin-group-l&id=11863 Geoff Clare writes: [...] I think the description of -e should be replaced by: -e When this option is on, if either * a pipeline, or * a simple command that is not in a pipeline fails for any of the reasons listed in Section 2.8.1 (on page 2315) or returns an exit status value >0, and is not part of the compound list following a while, until, or if keyword, and is not a part of an AND or OR list, and is not a pipeline beginning with the ! reserved word, then the shell shall immediately exit. -- Geoff Clare The Open Group, Thames Tower, Station Road, Reading, RG1 1LX, England