zsh-users
 help / color / mirror / code / Atom feed
* Alias help
@ 2021-04-26 22:55 Hoji, Aki
  2021-04-26 23:15 ` Eric Cook
  0 siblings, 1 reply; 8+ messages in thread
From: Hoji, Aki @ 2021-04-26 22:55 UTC (permalink / raw)
  To: zsh-users

Hi, 

I made a following alias and put it in .zshrc;

alias pu ="pip3 list -o | sed "1,2 d" |cut -d ' ' -f1 |  xargs -n1 pip3 install -U”

And when I restart zsh, I got a following error;

/Users/akhst7/.zshrc:109: pip3 list -o | sed 1,2 not found.  

I’d appreciate any help on fixing this.

Thanks in advance. 



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Alias help
  2021-04-26 22:55 Alias help Hoji, Aki
@ 2021-04-26 23:15 ` Eric Cook
  2021-04-27  7:10   ` zzapper
  2021-04-27 13:06   ` Akihiko Hohji
  0 siblings, 2 replies; 8+ messages in thread
From: Eric Cook @ 2021-04-26 23:15 UTC (permalink / raw)
  To: zsh-users

On 4/26/21 6:55 PM, Hoji, Aki wrote:
> alias pu ="pip3 list -o | sed "1,2 d" |cut -d ' ' -f1 |  xargs -n1 pip3 install -U”

As a shell function:
pu() {                                                                                                                 ~
   pip3 list -o   |
   sed "1,2 d"    |
   cut -d ' ' -f1 |
   xargs -n1 pip3 install -U
}

While not to the degree of say python, whitespace matters often in shell;
You have an extra space after the name of the alias pu, so the =word triggered a different
feature of zsh that expands the path to a command. in this case "pip3 list -o | sed 1,2"
once you remove the space you still have the problem of not quoting correctly.

alias pu='pip3 list -o | sed "1,2 d" |cut -d '\'' '\'' -f1 |  xargs -n1 pip3 install -U'

Is how to quote that command properly, which is less readable than a function is in my opinion.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Alias help
  2021-04-26 23:15 ` Eric Cook
@ 2021-04-27  7:10   ` zzapper
  2021-04-27 20:41     ` Bart Schaefer
  2021-04-29 13:30     ` Daniel Shahaf
  2021-04-27 13:06   ` Akihiko Hohji
  1 sibling, 2 replies; 8+ messages in thread
From: zzapper @ 2021-04-27  7:10 UTC (permalink / raw)
  To: zsh-users


On 27/04/2021 00:15, Eric Cook wrote:
> On 4/26/21 6:55 PM, Hoji, Aki wrote:
>> alias pu ="pip3 list -o | sed "1,2 d" |cut -d ' ' -f1 |  xargs -n1 
>> pip3 install -U”
>
> As a shell function:
> pu() { ~
>   pip3 list -o   |
>   sed "1,2 d"    |
>   cut -d ' ' -f1 |
>   xargs -n1 pip3 install -U
> }
>
> While not to the degree of say python, whitespace matters often in shell;
> You have an extra space after the name of the alias pu, so the =word 
> triggered a different
> feature of zsh that expands the path to a command. in this case "pip3 
> list -o | sed 1,2"
> once you remove the space you still have the problem of not quoting 
> correctly.
>
> alias pu='pip3 list -o | sed "1,2 d" |cut -d '\'' '\'' -f1 | xargs -n1 
> pip3 install -U'
>
> Is how to quote that command properly, which is less readable than a 
> function is in my opinion.
>
thanks for this explanation Eric (I've been having my own battles with 
shell white space recently)

When you are desperate to get something working not noticing a little 
thing like the extra space in >>>>alias pu ="pip3<<<

Pity we don't have an online script tester for zsh (many for bash)

I prefer an Alias to a Function where possible because it's easy to tab 
expand an alias and then if required tweak it




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Alias help
  2021-04-26 23:15 ` Eric Cook
  2021-04-27  7:10   ` zzapper
@ 2021-04-27 13:06   ` Akihiko Hohji
  1 sibling, 0 replies; 8+ messages in thread
From: Akihiko Hohji @ 2021-04-27 13:06 UTC (permalink / raw)
  To: zsh-users; +Cc: Eric Cook, zsh

HI Eric, 

Thanks for answering a newbie question.  As zzapper suggested, I might try keeping this command as a function.  

Aki 

> On Apr 26, 2021, at 7:15 PM, Eric Cook <llua@gmx.com> wrote:
> 
> On 4/26/21 6:55 PM, Hoji, Aki wrote:
>> alias pu ="pip3 list -o | sed "1,2 d" |cut -d ' ' -f1 |  xargs -n1 pip3 install -U”
> 
> As a shell function:
> pu() {                                                                                                                 ~
>  pip3 list -o   |
>  sed "1,2 d"    |
>  cut -d ' ' -f1 |
>  xargs -n1 pip3 install -U
> }
> 
> While not to the degree of say python, whitespace matters often in shell;
> You have an extra space after the name of the alias pu, so the =word triggered a different
> feature of zsh that expands the path to a command. in this case "pip3 list -o | sed 1,2"
> once you remove the space you still have the problem of not quoting correctly.
> 
> alias pu='pip3 list -o | sed "1,2 d" |cut -d '\'' '\'' -f1 |  xargs -n1 pip3 install -U'
> 
> Is how to quote that command properly, which is less readable than a function is in my opinion.
> 



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Alias help
  2021-04-27  7:10   ` zzapper
@ 2021-04-27 20:41     ` Bart Schaefer
  2021-04-29 13:30     ` Daniel Shahaf
  1 sibling, 0 replies; 8+ messages in thread
From: Bart Schaefer @ 2021-04-27 20:41 UTC (permalink / raw)
  To: zzapper; +Cc: Zsh Users

On Tue, Apr 27, 2021 at 12:11 AM zzapper <zsh@rayninfo.co.uk> wrote:
>
> Pity we don't have an online script tester for zsh (many for bash)

I haven't used it myself, and it's not online, but:
http://rocky.github.io/zshdb/


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Alias help
  2021-04-27  7:10   ` zzapper
  2021-04-27 20:41     ` Bart Schaefer
@ 2021-04-29 13:30     ` Daniel Shahaf
  2021-04-29 13:55       ` zzapper
  1 sibling, 1 reply; 8+ messages in thread
From: Daniel Shahaf @ 2021-04-29 13:30 UTC (permalink / raw)
  To: zzapper; +Cc: zsh-users

zzapper wrote on Tue, Apr 27, 2021 at 08:10:54 +0100:
> Pity we don't have an online script tester for zsh (many for bash)

What would that do, and why need it be online?

> I prefer an Alias to a Function where possible because it's easy to tab
> expand an alias and then if required tweak it

With a function, you run fned on it, then invoke edit-command-line and
delete the function's name on the first line, so you're left with an
anonymous function ready to be run.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Alias help
  2021-04-29 13:30     ` Daniel Shahaf
@ 2021-04-29 13:55       ` zzapper
  2021-04-29 14:13         ` Daniel Shahaf
  0 siblings, 1 reply; 8+ messages in thread
From: zzapper @ 2021-04-29 13:55 UTC (permalink / raw)
  To: zsh-users


On 29/04/2021 14:30, Daniel Shahaf wrote:
> zzapper wrote on Tue, Apr 27, 2021 at 08:10:54 +0100:
>> Pity we don't have an online script tester for zsh (many for bash)
> What would that do, and why need it be online?
>
>> I prefer an Alias to a Function where possible because it's easy to tab
>> expand an alias and then if required tweak it
> With a function, you run fned on it, then invoke edit-command-line and
> delete the function's name on the first line, so you're left with an
> anonymous function ready to be run.

# did you mean

zed -f myfunc


# thanks for the anonymous function tip



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Alias help
  2021-04-29 13:55       ` zzapper
@ 2021-04-29 14:13         ` Daniel Shahaf
  0 siblings, 0 replies; 8+ messages in thread
From: Daniel Shahaf @ 2021-04-29 14:13 UTC (permalink / raw)
  To: zzapper; +Cc: zsh-users

zzapper wrote on Thu, Apr 29, 2021 at 14:55:56 +0100:
> 
> On 29/04/2021 14:30, Daniel Shahaf wrote:
> > zzapper wrote on Tue, Apr 27, 2021 at 08:10:54 +0100:
> > > Pity we don't have an online script tester for zsh (many for bash)
> > What would that do, and why need it be online?
> > 
> > > I prefer an Alias to a Function where possible because it's easy to tab
> > > expand an alias and then if required tweak it
> > With a function, you run fned on it, then invoke edit-command-line and
> > delete the function's name on the first line, so you're left with an
> > anonymous function ready to be run.
> 
> # did you mean
> 
> zed -f myfunc

Yes.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-04-29 14:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-26 22:55 Alias help Hoji, Aki
2021-04-26 23:15 ` Eric Cook
2021-04-27  7:10   ` zzapper
2021-04-27 20:41     ` Bart Schaefer
2021-04-29 13:30     ` Daniel Shahaf
2021-04-29 13:55       ` zzapper
2021-04-29 14:13         ` Daniel Shahaf
2021-04-27 13:06   ` Akihiko Hohji

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).