Re: conditional aliases are broken

2011-08-19 Thread Chet Ramey
On 8/19/11 6:38 AM, Roman Rakus wrote: > On 08/18/2011 07:57 PM, Eric Blake wrote: >> On 08/18/2011 08:53 AM, Roman Rakus wrote: >>> On 08/18/2011 04:38 PM, Sam Steingold wrote: how do I write a function that would print the same as $ \ls | cat >>> f3(){ printf "%s\n" "$@"; } >> >> "\n" l

Re: conditional aliases are broken

2011-08-19 Thread Roman Rakus
On 08/18/2011 07:57 PM, Eric Blake wrote: On 08/18/2011 08:53 AM, Roman Rakus wrote: On 08/18/2011 04:38 PM, Sam Steingold wrote: how do I write a function that would print the same as $ \ls | cat f3(){ printf "%s\n" "$@"; } "\n" looks funny in shell; even though POSIX requires that "\n" doe

Re: conditional aliases are broken

2011-08-18 Thread Chet Ramey
On 8/18/11 11:58 AM, Greg Wooledge wrote: > It would appear "declare -g" does NOT allow you to "jump over" a local > variable that is shadowing a global. That's disappointing. That is not its intent. The very narrow purpose of declare -g is to allow you to declare a variable with attributes in

Re: conditional aliases are broken

2011-08-18 Thread Eric Blake
On 08/18/2011 08:53 AM, Roman Rakus wrote: On 08/18/2011 04:38 PM, Sam Steingold wrote: how do I write a function that would print the same as $ \ls | cat f3(){ printf "%s\n" "$@"; } "\n" looks funny in shell; even though POSIX requires that "\n" does not treat the \ as an escape but as a li

Re: conditional aliases are broken

2011-08-18 Thread Eric Blake
On 08/18/2011 11:38 AM, Stefano Lattarini wrote: Hi Eric. On Thursday 18 August 2011, Eric Blake wrote: On 08/18/2011 08:44 AM, Eric Blake wrote: how do I write a function that would print the same as $ \ls | cat Useless use of cat. This can be done with \ls -1. f(){ for a in "$@"; do ech

Re: conditional aliases are broken

2011-08-18 Thread Stefano Lattarini
On Thursday 18 August 2011, Stefano Lattarini wrote: > Hi Eric. > > On Thursday 18 August 2011, Eric Blake wrote: > > On 08/18/2011 08:44 AM, Eric Blake wrote: > > >> how do I write a function that would print the same as > > >> $ \ls | cat > > > > Useless use of cat. This can be done with \ls -

Re: conditional aliases are broken

2011-08-18 Thread Stefano Lattarini
Hi Eric. On Thursday 18 August 2011, Eric Blake wrote: > On 08/18/2011 08:44 AM, Eric Blake wrote: > >> how do I write a function that would print the same as > >> $ \ls | cat > > Useless use of cat. This can be done with \ls -1. > > > f(){ for a in "$@"; do echo "$a"; done; } > > Or skip the

Re: conditional aliases are broken

2011-08-18 Thread Linda Walsh
` Greg Wooledge wrote: On Thu, Aug 18, 2011 at 08:03:41AM -0700, Linda Walsh wrote: 4.2 introduce a new -g to declare a global variable inside a function. Which doesn't say what it would do in situations like the above. Then let's test: imadev:~$ echo $BASH_VERSION

Re: conditional aliases are broken

2011-08-18 Thread Greg Wooledge
On Thu, Aug 18, 2011 at 08:03:41AM -0700, Linda Walsh wrote: > >4.2 introduce a new -g to declare a global variable inside a function. > >Which doesn't say what it would do in situations like the above. Then let's test: imadev:~$ echo $BASH_VERSION 4.2.10(7)-release imadev:~$ unset a b;

Re: conditional aliases are broken

2011-08-18 Thread Linda Walsh
Pierre Gaston wrote: Is this a question? or are you trying to make a point? It is both -- a chance to find answer to a question, or make the point that aliases in scripts have a useful purposes that can't be replaced by function clls. For the question (If I understand correctly): 1) Most

Re: conditional aliases are broken

2011-08-18 Thread Roman Rakus
On 08/18/2011 04:38 PM, Sam Steingold wrote: how do I write a function that would print the same as $ \ls | cat f3(){ printf "%s\n" "$@"; } But please move your question like "HOW TO..." somewhere else; comp.unix.shell usenet group or the #bash IRC channel on freenode or... This mailing list

Re: conditional aliases are broken

2011-08-18 Thread Eric Blake
On 08/18/2011 08:44 AM, Eric Blake wrote: how do I write a function that would print the same as $ \ls | cat Useless use of cat. This can be done with \ls -1. f(){ for a in "$@"; do echo "$a"; done; } Or skip the loop altogether: f(){ printf %s\\n "%@"; } -- Eric Blake ebl...@redhat.co

Re: conditional aliases are broken

2011-08-18 Thread Eric Blake
On 08/18/2011 08:38 AM, Sam Steingold wrote: mkdir z cd z touch a b 'c d' When doing exercises like this, I like to: touch a b 'c d' Notice the double spacing - it proves whether I used enough quoting throughout the exercise - if 'c d' with one space shows up anywhere, then I missed quotin

Re: conditional aliases are broken

2011-08-18 Thread Sam Steingold
> * Eric Blake [2011-08-15 16:59:29 -0600]: > > On 08/15/2011 04:40 PM, Sam Steingold wrote: >>> * Andreas Schwab [2011-08-15 22:04:04 +0200]: >>> >>> Sam Steingold writes: >>> Cool. Now, what does this imply? >>> >>> "For almost every purpose, shell functions are preferred over aliase

Re: conditional aliases are broken

2011-08-18 Thread Greg Wooledge
On Wed, Aug 17, 2011 at 08:46:34PM -0700, Linda Walsh wrote: > how do you declare a variable for storage in the context of the caller? > (using a function)... > ??? The *caller* declares it. > I found it very troublesome > inside a function, to store a value into a local variable in the caller.

Re: conditional aliases are broken

2011-08-18 Thread Pierre Gaston
On Thu, Aug 18, 2011 at 6:46 AM, Linda Walsh wrote: > > > > ` Eric Blake wrote: >> >> On 08/15/2011 04:40 PM, Sam Steingold wrote: * Andreas Schwab  [2011-08-15 22:04:04 +0200]: Sam Steingold  writes: > > Cool.  Now, what does this imply?    "For almost every purpo

Re: conditional aliases are broken

2011-08-17 Thread Linda Walsh
` Eric Blake wrote: On 08/15/2011 04:40 PM, Sam Steingold wrote: * Andreas Schwab [2011-08-15 22:04:04 +0200]: Sam Steingold writes: Cool. Now, what does this imply? "For almost every purpose, shell functions are preferred over aliases." so, how do I write alias a=b as a function? (

Re: conditional aliases are broken

2011-08-15 Thread Eric Blake
On 08/15/2011 04:40 PM, Sam Steingold wrote: * Andreas Schwab [2011-08-15 22:04:04 +0200]: Sam Steingold writes: Cool. Now, what does this imply? "For almost every purpose, shell functions are preferred over aliases." so, how do I write alias a=b as a function? (remember that argu

Re: conditional aliases are broken

2011-08-15 Thread Sam Steingold
> * Andreas Schwab [2011-08-15 22:04:04 +0200]: > > Sam Steingold writes: > >> Cool. Now, what does this imply? > >"For almost every purpose, shell functions are preferred over aliases." so, how do I write alias a=b as a function? (remember that arguments may contain spaces &c) -- Sam S

Re: conditional aliases are broken

2011-08-15 Thread Andreas Schwab
Sam Steingold writes: > Cool. Now, what does this imply? "For almost every purpose, shell functions are preferred over aliases." 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 dif

Re: conditional aliases are broken

2011-08-15 Thread Eric Blake
On 08/15/2011 01:10 PM, Sam Steingold wrote: * Andreas Schwab [2011-08-15 18:42:30 +0200]: Sam Steingold writes: this works: $ alias z='echo a' $ zz(){ z b; } $ zz a b however, after sourcing this file: if true; then alias z='echo a' zz(){ z b; } fi Aliases are expanded during read

Re: conditional aliases are broken

2011-08-15 Thread Sam Steingold
> * Andreas Schwab [2011-08-15 18:42:30 +0200]: > > Sam Steingold writes: > >> this works: >> >> $ alias z='echo a' >> $ zz(){ z b; } >> $ zz >> a b >> >> however, after sourcing this file: >> if true; then >> alias z='echo a' >> zz(){ z b; } >> fi > > Aliases are expanded during reading, but

Re: conditional aliases are broken

2011-08-15 Thread Andreas Schwab
Sam Steingold writes: > this works: > > $ alias z='echo a' > $ zz(){ z b; } > $ zz > a b > > however, after sourcing this file: > if true; then > alias z='echo a' > zz(){ z b; } > fi Aliases are expanded during reading, but the alias command isn't executed until after the complete compound c