String Concatenation with $'\NNN' Error
Configuration Information [Automatically generated, do not change]: Machine: i686 OS: linux-gnu Compiler: i686-pc-linux-gnu-gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -O2 -march=pentium3 -pipe uname output: Linux steelbox 2.6.27.10 #11 Mon Mar 2 19:48:16 CST 2009 i686 AMD Athlon(tm) XP 3000+ AuthenticAMD GNU/Linux Machine Type: i686-pc-linux-gnu Bash Version: 3.2 Patch Level: 39 Release Status: release Description: This command sequence concatenates a text string with a $'\NNN' string producing an error: shopt -s extglob; x="hello"$'\179'; echo "${x//+([^[:print:]])/?}" EXPECTED RESULT IS -> hello? HOWEVER, THE RESULT THAT IS PRODUCED IS -> hello?9 Repeat-By: Reproduce by running the above command sequence.
read built-in will not read inside while loop
Configuration Information [Automatically generated, do not change]: Machine: i686 OS: linux-gnu Compiler: i686-pc-linux-gnu-gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' -DC uname output: Linux tony 2.6.12-gentoo-r10 #14 Thu Sep 29 03:19:53 CDT 2005 i686 AMD Athlon(tm) XP 3000+ AuthenticAMD GNU/Lin Machine Type: i686-pc-linux-gnu Bash Version: 3.0 Patch Level: 16 Release Status: release Description: When a 'read -p "line of text."' built-in is placed inside a while loop which has redirected input to another read built-in, the read command inside the while loop does not execute. I know this sounds vague, but see the example and it will make more sense. Repeat-By: #!/bin/bash read -p "hello press a key." while read a b c ; do echo $a read -p "Looping.. press a key." <--- This 'read' will not execute. echo $b echo $c done < <(ls -al ~/) exit 0 ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash
inconsistent output for cd
Configuration Information [Automatically generated, do not change]: Machine: i686 OS: cygwin Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash.exe' -DCONF_HOSTTYPE='i686' -DCONF_OSTYPE='cygwin' -DCONF_MACHTYPE='i686-pc-cygwin' -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -DRECYCLES_PIDS -I. -I/home/eblake/bash-3.2.15-13/src/bash-3.2 -I/home/eblake/bash-3.2.15-13/src/bash-3.2/include -I/home/eblake/bash-3.2.15-13/src/bash-3.2/lib -O2 -pipe uname output: CYGWIN_NT-5.1 nycutbalil 1.5.24(0.156/4/2) 2007-01-31 10:57 i686 Cygwin Machine Type: i686-pc-cygwin Bash Version: 3.2 Patch Level: 15 Release Status: release Description: Sometimes cd echos the new directory, sometimes it doesn't. This makes picking up a new directory in an overridden cd function painful: cd () { local oldd=$(pwd) local newd=$(command cd "$@" 2>/dev/null 1>&2 && pwd 2>/dev/null) # echo oldd="<$oldd>" # echo newd="<$newd>" if [[ $newd == "" ]]; then echo "cd $* failed" 1>&2 elif [[ $oldd == $newd ]]; then echo "cd $* - no change" 1>&2 else # do extra cd processing here command cd "$@" 2>/dev/null 1>&2 # do extra cd processing here fi } In the assignment of newd, curiously, we get either one line or two! newd should be just the new directory (the result of running built-in cd in a subshell) but since it sometimes outputs a result (which seems to bypass the output redirection), newd may end up with two separate directories in two lines. It seems like this extra output only occurs when CDPATH is used for the cd operation. Also, popd and pushd also have similarly inconvenient outputs. None of this is documented in the manual, and there appear to be no options at all to turn this superfluous output off. Repeat-By: Try the above function, with the commented lines uncommented. Use it to change to a directory in the CDPATH. Check the newd=... output. Fix: Don't use CDPATH! But that's a shame... ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash
Re: inconsistent output for cd
Quoting Chet Ramey <[EMAIL PROTECTED]>: > > On Tue, 3 Apr 2007, Chet Ramey wrote: > > > > It is an interesting position for POSIX to take, given that in general > > Unix is silent on success. > > It's the logical thing to do, considering the potential ambiguity that > exists when you use a directory selected from CDPATH. The illogical thing > is that POSIX requires the output even when the shell is not interactive. > > > Does POSIX forbid an option "to turn this superfluous output off", as > > Tony Balinski put it? > > Redirect stdout to /dev/null. That's the conventional way to rid yourself > of superfluous output. > This is where I find an inconsistency. With the function I gave, cd () { local oldd=$(pwd); local newd=$(command cd "$@" 2>/dev/null 1>&2 && pwd 2>/dev/null); echo oldd="<$oldd>"; echo newd="<$newd>"; if [[ $newd == "" ]]; then echo "cd $* failed" 1>&2; else if [[ $oldd == $newd ]]; then echo "cd $* - no change" 1>&2; else command cd "$@" 2> /dev/null 1>&2; fi; fi } Running bash on Cygwin (taken from Cygwin): version: GNU bash, version 3.2.15(13)-release (i686-pc-cygwin) Copyright (C) 2005 Free Software Foundation, Inc. the redirection in the assignment of newd for "command cd" doesn't work (when cd generates output). I have a CDPATH=.:/home/tbalinski; now when I use my cd function to go from MiscDocs to Dev (both in /home/tbalinski) I get: $ cd Dev oldd= newd= $ i.e. the newd variable was assigned both the output of cd (which should have gone to /dev/null) and of the pwd that follows it, rather than just the pwd. (I also tried "1>/dev/null 2>&1" for the redirects, same results). Curiously, under the same conditions on a Red Hat Linux box: version: GNU bash, version 2.05b.0(1)-release (i386-redhat-linux-gnu) Copyright (C) 2002 Free Software Foundation, Inc. I get the behaviour I expected: only one line in newd: $ cd Dev oldd= newd= $ Either something strange is going on with the Cygwin compatibility layer or there is a problem with the later bash. Or am I writing my command wrongly? Thanks, Tony ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash
how do I write a shell script to batch rename files in a directory?
Hello all, I have a directory listing of files like: img.bc03.547.1.gif? I need to trim the last character off for each file in the dir. I know I can use: mv img.bc03.547.1.gif? img.bc03.547.1.gif to rename each by hand, but I want to do this as a batch. I know it would start with: for files in *; do; after that, I'm stuck! Any suggestions?
implementing flow control in bash
Hello all, I'm sure this isn't a bug, but just my inability to wrap my head around enough of bash flow control: I wrote the following shell script to find all gifs in a directory. Then use "identify" from imagemagick to grab the gif width. Then, print the image name and width to a file. for i in `find . -name \*gif`; do identify -format "$i %w" $i; done > results.txt Then, I used a ruby script to cull only those images with a width over 570 pixels. So, problem solved, but I wanted to see if I could do it all in bash. More specifically, (if this makes sense) I want to "do identify -format "$i %w" $i" only for those "$i %w" where "%w" is > 570. The above script will give me output like: image1.gif 360 image2.gif 780 But I want it to give me: image1.gif 360 In pseudo-code, I want something like: for i in `find . -name \*gif`; do identify -format "$i %w" $i if [%w > 570]; done > results.txt Any suggestions? Tony
Re: implementing flow control in bash
Works perfectly, thanks! I'll study up on the syntax... Tony On Tue, Oct 21, 2008 at 5:30 PM, Bernd Eggink <[EMAIL PROTECTED]> wrote: > Tony Zanella schrieb: >> >> Hello all, >> I'm sure this isn't a bug, but just my inability to wrap my head >> around enough of bash flow control: >> I wrote the following shell script to find all gifs in a directory. >> Then use "identify" from imagemagick to grab the gif width. Then, >> print the image name and width to a file. >> >> for i in `find . -name \*gif`; do identify -format "$i %w" $i; done >>> >>> results.txt >> >> Then, I used a ruby script to cull only those images with a width over >> 570 pixels. So, problem solved, but I wanted to see if I could do it >> all in bash. >> More specifically, (if this makes sense) I want to "do identify >> -format "$i %w" $i" only for those "$i %w" where "%w" is > 570. >> >> The above script will give me output like: >> >> image1.gif 360 >> image2.gif 780 >> >> But I want it to give me: >> >> image1.gif 360 >> >> In pseudo-code, I want something like: >> >> for i in `find . -name \*gif`; do identify -format "$i %w" $i if [%w >>> >>> 570]; done > results.txt > > for i in $(find -name '*.gif') > do >w=$(identify -format %w $i) >(( w > 570 )) && echo "$i $w" > done > > Hope that helps, > Bernd > > -- > Bernd Eggink > http://sudrala.de >
Re: loop through records
awk may be a help here. Using it, you can refer to fields, like so: $ cat f1 187431346 0323 mirrored 11866 187431346 0324 mirrored 11866 187431346 0325 mirrored 11866 187431346 0326 mirrored 11866 $ awk '{print $1;print$2}' f1 187431346 0323 187431346 0324 187431346 0325 187431346 0326 On Wed, Mar 11, 2009 at 4:11 PM, OnTheEdge wrote: > > All, I'm trying to figure out how to loop through an array of records (if > possible) and reference fields in that record, but I've only been able to > reference the entire array (array[0]) or when assigned with parens, there is > no concept of a row... > > #!/bin/bash > > array1="187431346 0323 mirrored 11866 > 187431346 0324 mirrored 11866 > 187431346 0325 mirrored 11866 > 187431346 0326 mirrored 11866" > > element_count1=${#array1[*]} > echo $element_count1 > > number_of_elements=${#arra...@]} > > echo '- ARRAY-1' > > for REC in "${array1[*]}" > do > echo "Field 1: ${REC[0]} Field 2: ${REC[1]}" > done > > I would like to see something like this: > Field 1: 187431346 Field 2: 0323 > Field 1: 187431346 Field 2: 0324 > Field 1: 187431346 Field 2: 0325 > Field 1: 187431346 Field 2: 0326 > > Thanks > -- > View this message in context: > http://www.nabble.com/loop-through-records-tp22463462p22463462.html > Sent from the Gnu - Bash mailing list archive at Nabble.com. > > > >
Re: Bash Bug: Concatenating String with $'\NNN' Error
I just sent a bug report with the above description; please ignore.. I'm an idiot. There is no error actually my math was bad.
Bash 4 cursor in my prompt
This ever get solved? I had the same issue in bash v3.2x and the root cause was the formatting. Let me know if you want more info - Thanks. --
Re: Bash 4 cursor in my prompt
yeah - the issue on my system was that I was not using the start-of and end-of color characters properly - for example: = ORIGINAL PS1 STRING = export PS1="[\e[1;36m\w @ \h\e[m] \n[\e[1;35m\t \u\e[m] > " = NEW PS1 STRING = export PS1="[\[\033[1;36m\]\w @ \h\[\033[0m]\n\][\[\033[1;35m\t \u\]\[\033[0m\]] > " Note that I removed the "\033" entries and also added the "[\e[" & "[\e[m" control characters. Once I made these slight changes, it solved the issue... -- *** * | * * | Tony Leding * * | | | Software Engineer, Cisco Systems * *:|: :|: | CMTS-BU / Cable System Test * * :|||: :|||:| Office: 408-525-2995 * * .:|:...:|:. | Mobile: 925-708-9757 * * | E-mail: tled...@cisco.com* * Cisco Systems | * *** Chet Ramey wrote: >> This ever get solved? I had the same issue in bash v3.2x and the root cause >> was the formatting. > > If it's the one I'm thinking of, nobody was ever able to reproduce it. > > Chet >
bash script problems
Hello, I am having issues with a bash script and I was wondering if anyone could be of assistance? Its just that our lecturer assumed it would be easy to pick up and do an assignment on, even though we haven't learnt it and its not a pre-requisite. But anyway, I noticed when I use the cut command to obtain some numbers from a file, I cannot use it in an arithmetic operation. I tried the following: temp='expr $val1 + $val2' But I get the following error message: expr: non-numeric argument I was wondering if BASH requires type conversion? I even printed out the values for $val1 and $val2. They look like integers to me. If anyone could help me, it would be greatly appreciated. Thanks in advance Tony ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash
Re: bash script problems
"Chris F.A. Johnson" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > When quoting parts of a script or error messages, please be > accurate (cut and paste rather than retyping). You used: > > temp=`expr $val1 + $val2` > > or you wouldn't have received that error. The line you have would > have assigned the literal value to $temp. > Oh those were meant to be single quotes. temp='expr $val1 + $val2' > What are the values of $val1 and $val2? Use this command to see > them: > > printf ":%s:%s:\n" "$val1" "$val2" > > What is the result of: > > echo $(( $val1 + $val2 )) > > What command did you use to fill those variables? > Those lines didn't seem to print out anything unforunately It prints out values when I simply type the variable name though. The variable holds the following: val1='cut -c8-9 usrTime' val2='cut -c7-8 sysTime' ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash
Re: bash script problems
"William Park" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Note the difference between `...` and '...' Sorry if they came out weird on the newsgroups, but they were meant to be single quotes ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash
Re: bash script problems
Oh sorry. Didn't look at it closely enough. Thanks, that did solve most of the issues, but now I'm just wondering if the following is valid? temp=`expr $val1 + $val2` $temp > file Everything besides this seems to be working fine now ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash
Re: bash script problems
Got it working. ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash
Issue about AIX
Hi, On AIX, like Solaris, when root, the test "test -x /tmp/AFile" returns true even if the file is not executable. This issue is there for ages. Here attached is the patch for fixing it for v5.0 . Would you mind adding it to the source code of bash ? Thanks/Regards, Tony --- ./lib/sh/eaccess.c.ORIGIN 2019-03-06 16:15:23 +0100 +++ ./lib/sh/eaccess.c 2019-03-06 16:16:20 +0100 @@ -213,10 +213,10 @@ # else /* HAVE_EACCESS */ /* FreeBSD */ ret = eaccess (path, mode); /* XXX -- not always correct for X_OK */ # endif /* HAVE_EACCESS */ -# if defined (__FreeBSD__) || defined (SOLARIS) +# if defined (__FreeBSD__) || defined (SOLARIS) || defined(_AIX) if (ret == 0 && current_user.euid == 0 && mode == X_OK) return (sh_stataccess (path, mode)); -# endif /* __FreeBSD__ || SOLARIS */ +# endif /* __FreeBSD__ || SOLARIS || _AIX */ return ret; #elif defined (EFF_ONLY_OK) /* SVR4(?), SVR4.2 */ return access (path, mode|EFF_ONLY_OK); @@ -232,7 +232,7 @@ if (current_user.uid == current_user.euid && current_user.gid == current_user.egid) { ret = access (path, mode); -#if defined (__FreeBSD__) || defined (SOLARIS) +#if defined (__FreeBSD__) || defined (SOLARIS) || defined(_AIX) if (ret == 0 && current_user.euid == 0 && mode == X_OK) return (sh_stataccess (path, mode)); #endif
RE: Issue about AIX
if access is permitted for the invoker of the current process. The real user and group IDs, the concurrent group set, and the privilege of the invoker are used for the calculation. Note: The expression access (PathName, Mode) is equivalent to accessx (PathName, Mode, ACC_INVOKER). ACC_OTHERS Determines if the specified access is permitted for any user other than the object owner. The Mode parameter must contain only one of the valid modes. Privilege is not considered in the calculation. ACC_ALL Determines if the specified access is permitted for all users. The Mode parameter must contain only one of the valid modes. Privilege is not considered in the calculation . Note: The accessx subroutine shows the same behavior by both the user and root with ACC_ALL. DirFileDescriptor Specifies the file descriptor of an open directory, which is used as the effective current working directory for the PathName argument. If the DirFileDescriptor parameter equals AT_FDCWD, the DirFileDescriptor parameter is ignored and the PathName argument specifies the complete file. Flag Specifies a bit field argument. If the Flag parameter equals AT_EACCESS, the effective user and group IDs are checked (ACC_SELF). If the Flag parameter is zero, the real IDs are checked (ACC_INVOKER). Return Values If the requested access is permitted, the access, accessx, faccessx, accessxat, and faccessat subroutines return a value of 0. If the requested access is not permitted or the function call fails, a value of -1 is returned and the errno global variable is set to indicate the error. The access subroutine indicates success for X_OK even if none of the execute file permission bits are set. Error Codes The access faccessat, accessx, and accessx subroutines fail if one or more of the following are true: Item Description EACCES Search permission is denied on a component of the PathName prefix. EFAULT The PathName parameter points to a location outside the allocated address space of the process. ELOOP Too many symbolic links were encountered in translating the PathName parameter. ENAMETOOLONG A component of the PathName parameter exceeded 255 characters or the entire PathName parameter exceeded 1022 characters. ENOENT A component of the PathName does not exist or the process has the disallow truncation attribute set. ENOENT The named file does not exist. ENOENT The PathName parameter was null. ENOENT A symbolic link was named, but the file to which it refers does not exist. ENOTDIR A component of the PathName is not a directory. ESTALE The process root or current directory is located in a virtual file system that has been unmounted. The faccessx subroutine fails if the following is true: Item Description EBADF The value of the FileDescriptor parameter is not valid. The access, accessx, and faccessx subroutines fail if one or more of the following is true: Item Description EACCES The file protection does not allow the requested access. ENOMEM Unable to allocate memory. EIO An I/O error occurred during the operation. EROFS Write access is requested for a file on a read-only file system. The accessxat and faccessat subroutines fail if one or more of the following settings are true: Item Description EBADF The PathName parameter does not specify an absolute path and the DirFileDescriptor argument is neither AT_FDCWD nor a valid file descriptor. EINVAL The value of the Flag parameter is not valid. ENOTDIR The PathName parameter is not an absolute path and DirFileDescriptor is a file descriptor but is not associated with a directory. If Network File System (NFS) is installed on your system, the accessx, accessxat, and faccessx subroutines can also fail if the following settings are true: Item Description ETIMEDOUT The connection timed out. ETXTBSY Write access is requested for a shared text file that is being executed. EINVAL The value of the Mode argument is invalid. Cordialement, Tony Reix tony.r...@atos.net ATOS / Bull SAS ATOS Expert IBM Coop Architect & Technical Leader Office : +33 (0) 4 76 29 72 67 1 rue de Provence - 38432 Échirolles - France www.atos.net<https://mail.ad.bull.net/owa/redir.aspx?C=PvphmPvCZkGrAgHVnWGsdMcDKgzl_dEIsM6rX0g