Re: Problem with how to assign an array
"Steven W. Orr" writes: > 517 > r=($(eval echo "\${${a_all[1]}[@]}")) If you use $(eval echo ...) you are almost always doing it wrong. eval "r=(\"\${${a_all[1]}[@]}\")" Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
Re: bash tab variable expansion question?
Eric Blake writes: > On 02/24/2011 03:14 PM, Michael Kalisz wrote: >> $ echo $PWD/ >> will expand the $PWD variable to your current directory >> >> while in bash, version 4.2.0(1)-release: >> >> $ echo $PWD/ >> will just escape the $ in front of the $ variable i.e: >> >> $ echo \$PWD/ >> The shell-expand-line (Ctrl-Alt-e) works but before I could use just TAB >> >> Any hints why? Any way to get the 4.1 behavior in 4.2? >> >> Can someone confirm... Is this a bug or a feature? > > I'm not the developer, but in my mind, this is a welcome feature. Looks like you didn't read what Michael wrote. > TAB-completion should NOT modify what I typed, Except that it does. $PWD/ and \$PWD/ are quite different things. Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
Re: bash tab variable expansion question?
On Friday 25 Feb 2011 05:15:24 Eric Blake wrote: > On 02/24/2011 03:14 PM, Michael Kalisz wrote: > > $ echo $PWD/ > > will expand the $PWD variable to your current directory > > > > while in bash, version 4.2.0(1)-release: > > > > $ echo $PWD/ > > will just escape the $ in front of the $ variable i.e: > > > > $ echo \$PWD/ > > The shell-expand-line (Ctrl-Alt-e) works but before I could use just TAB > > > > Any hints why? Any way to get the 4.1 behavior in 4.2? > > > > Can someone confirm... Is this a bug or a feature? > > I'm not the developer, but in my mind, this is a welcome feature. > TAB-completion should NOT modify what I typed, and I consider the 4.1 > behavior to be the bug. Maybe, but then it shouldn't escape the $ either, as the OP is reporting for 4.2 (I don't have a 4.2 handy to test it). -- D.
Re: bash tab variable expansion question?
On Fri, Feb 25, 2011 at 5:46 PM, Davide Brini wrote: > On Friday 25 Feb 2011 05:15:24 Eric Blake wrote: > > > On 02/24/2011 03:14 PM, Michael Kalisz wrote: > > > $ echo $PWD/ > > > will expand the $PWD variable to your current directory > > > > > > while in bash, version 4.2.0(1)-release: > > > > > > $ echo $PWD/ > > > will just escape the $ in front of the $ variable i.e: > > > > > > $ echo \$PWD/ > > > The shell-expand-line (Ctrl-Alt-e) works but before I could use just > TAB > > > > > > Any hints why? Any way to get the 4.1 behavior in 4.2? > > > > > > Can someone confirm... Is this a bug or a feature? > > > > I'm not the developer, but in my mind, this is a welcome feature. > > TAB-completion should NOT modify what I typed, and I consider the 4.1 > > behavior to be the bug. > > Maybe, but then it shouldn't escape the $ either, as the OP is reporting > for > 4.2 (I don't have a 4.2 handy to test it). > > Agree, $ should not be escaped here which is different from pathname completion. -- Clark J. Wang
Re: bash tab variable expansion question?
On Fri, Feb 25, 2011 at 1:15 PM, Eric Blake wrote: > On 02/24/2011 03:14 PM, Michael Kalisz wrote: > > $ echo $PWD/ > > will expand the $PWD variable to your current directory > > > > while in bash, version 4.2.0(1)-release: > > > > $ echo $PWD/ > > will just escape the $ in front of the $ variable i.e: > > > > $ echo \$PWD/ > > The shell-expand-line (Ctrl-Alt-e) works but before I could use just TAB > > > > Any hints why? Any way to get the 4.1 behavior in 4.2? > > > > Can someone confirm... Is this a bug or a feature? > > I'm not the developer, but in my mind, this is a welcome feature. > TAB-completion should NOT modify what I typed, It's not true, see this discussion: http://lists.gnu.org/archive/html/bug-bash/2011-02/msg00163.html > and I consider the 4.1 > behavior to be the bug. I'd like to view it as a feature. ;) > Consider if I have parallel directory > structures a/c and b/c. If I do: > > d=a > $d/c/test > d=b > $d/c/test > > I want to run two different programs. Now, instead of a one-letter > name, consider that it is something longer, like $HOME. If typing TAB > expands the variable, instead of keeping it intact, then I can't do: > > $HOME/c/t-TAB > $HOME=b > UP-UP-ENTER > > to repeat my test in a new directory, since tab completion wiped out > that I want to evaluate $HOME every time. (The same goes for command > substitution - bash should never pre-maturely lock me in to a single > expansion during tab completion.) > > -- > Eric Blake ebl...@redhat.com+1-801-349-2682 > Libvirt virtualization library http://libvirt.org > > -- Clark J. Wang
Re: Problem with how to assign an array
On Thu, Feb 24, 2011 at 06:59:02PM -0500, Steven W. Orr wrote: > I intentionally used the star instead of the atsign because I'm taking > advantage of the fact that these array elements all have no whitespace. So, > after the assignment to a_all, the value of a[0] is equal to the single > string represented by "${a1[*]}" (with quotes). So you're trying to make an array of arrays? To fake a two-dimensional matrix? Should've said so. The only sane way to do this is to make an associative array whose keys are a tuple of the indices you want. (Or, if the indices are strictly numeric, and bounded, you can do it with regular sparse non-associative arrays by making the keys i*100+j where 100 is some constant chosen to be larger than the bound on j.) And, of course, there's always "don't write it in bash". That's often a sane answer. AA example: declare -A big big[$i,$j]=foo Numeric index example: big[i*100+j]=foo If you actually wanted an "array of lists" or something that's *not* mimicking a matrix, then, well, good luck. (Did I mention that there are other languages besides bash? Some of them actually HAVE such data structures.)
Re: bash tab variable expansion question?
On Fri, Feb 25, 2011 at 09:46:58AM +, Davide Brini wrote: > Maybe, but then it shouldn't escape the $ either, as the OP is reporting for > 4.2 (I don't have a 4.2 handy to test it). I actually noticed this quite recently, but didn't think to bring it up. I had just typed some "cd" command, and then realized I wanted to view a file in the directory where I had just been. So instead of changing directory again, I typed "cd $OLDPWD/foo" -- and the $OLDPWD became \$OLDPWD and did not do as I wished. Fortunately the workaround was simple enough -- once the filename had been completed I went back and x'ed out the \.
Re: bash tab variable expansion question?
Greg Wooledge writes: > Fortunately the workaround was simple enough -- once the filename had > been completed I went back and x'ed out the \. Or use ~-/. Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
Bash-4.1 Official Patch 10
BASH PATCH REPORT = Bash-Release: 4.1 Patch-ID: bash41-010 Bug-Reported-by:Stephane Jourdois Bug-Reference-ID: Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-bash/2010-05/msg00165.html Bug-Description: The expansion of the \W prompt string escape sequence incorrectly used strcpy to copy overlapping strings. Only memmove works in this case. Patch (apply with `patch -p0'): *** ../bash-4.1-patched/parse.y 2009-12-30 12:51:42.0 -0500 --- parse.y 2011-02-24 16:40:48.0 -0500 *** *** 5153,5157 t = strrchr (t_string, '/'); if (t) ! strcpy (t_string, t + 1); } } --- 5153,5157 t = strrchr (t_string, '/'); if (t) ! memmove (t_string, t + 1, strlen (t)); } } *** ../bash-4.1-patched/y.tab.c 2009-12-30 12:52:02.0 -0500 --- y.tab.c 2011-02-24 16:50:27.0 -0500 *** *** 7482,7486 t = strrchr (t_string, '/'); if (t) ! strcpy (t_string, t + 1); } } --- 7482,7486 t = strrchr (t_string, '/'); if (t) ! memmove (t_string, t + 1, strlen (t)); } } *** *** 8244,8246 } #endif /* HANDLE_MULTIBYTE */ - --- 8244,8245 *** ../bash-4.1-patched/patchlevel.h2009-10-01 16:39:22.0 -0400 --- patchlevel.h2010-01-14 09:38:08.0 -0500 *** *** 26,30 looks for to find the patch level (for the sccs version string). */ ! #define PATCHLEVEL 9 #endif /* _PATCHLEVEL_H_ */ --- 26,30 looks for to find the patch level (for the sccs version string). */ ! #define PATCHLEVEL 10 #endif /* _PATCHLEVEL_H_ */ -- ``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/
Re: Problem with how to assign an array
On 2/25/2011 4:22 AM, Andreas Schwab wrote: "Steven W. Orr" writes: 517> r=($(eval echo "\${${a_all[1]}[@]}")) If you use $(eval echo ...) you are almost always doing it wrong. eval "r=(\"\${${a_all[1]}[@]}\")" Andreas. Thanks. I changed things of the form r=($(eval "echo "\${${a_all[1]}[@]}\"")) to eval "r=(\"\${${a_all[1]}[@]}\")" One place where I can't see how to eliminate the construct is where I pass in the name of an array and parse it using set set -- $(eval echo \"\${$name[@]}\") would I be better off with something like eval "set -- \"\${$name[@]}\"" ? TIA -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net
Re: bash tab variable expansion question?
Look at the following example: # touch 'file name with a space' if I press # ll file then I get: # ll file\ name\ with\ a\ space -rw-r--r-- 1 root sys 0 Feb 25 13:10 file name with a space The backslash '\' which reminds me of: # cd /tmp # mkdir hello # cd $PWD/hello Which gives me: # cd \$PWD/hello instead # cd /tmp/hello (if I press ESC Ctrl-e twice it when the \$PWD is diplayd the it will expand the $PWD variable correctly) Anyhow...This "feature" seems new to 4.2.0 and differs from previous bash versions. Any hints how the get back the old behavior? //Michael
Re: bash tab variable expansion question?
What do you mean? ~-/. is no equal to $PWD On 25 Feb, 16:03, Andreas Schwab wrote: > Greg Wooledge writes: > > Fortunately the workaround was simple enough -- once the filename had > > been completed I went back and x'ed out the \. > > Or use ~-/. > > Andreas. > > -- > Andreas Schwab, sch...@linux-m68k.org > GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 > "And now for something completely different."
Re: bash tab variable expansion question?
gnu.bash.bug wrote: > Andreas Schwab wrote: > > Greg Wooledge wrote: > > > directory again, I typed "cd $OLDPWD/foo" -- and the $OLDPWD > > > became \$OLDPWD and did not do as I wished. > > > > Or use ~-/. > > What do you mean? > > ~-/. is no equal to $PWD No. But it is similar to $OLDPWD which is what Greg had written about. Bob