hao
hao

Reputation: 10228

How can I pipe this echo at the end of this line instead of at the beginning, in zsh?

Right now I have

echo 'abcdef' | gzip | wc -c

What I would like to have is

$(| gzip | wc -c) ???mystery-pipe-operator??? echo 'abcdef'

or

$(gzip | wc -c) <(echo 'abcdef')

But neither of them work, of course, because I don't know what I'm doing. I want to restructure the echo to the end so that I can edit the string easily when I press up and down to navigate my command-line history. I'm using zsh. I know about Ctrl-R to do a reverse incremental search, but it's too much of a hassle.

Thanks!

Upvotes: 0

Views: 598

Answers (2)

Michał Politowski
Michał Politowski

Reputation: 4385

In zsh (and also in bash) you can use a compound command together with process substitution:

{ gzip | wc -c; } < <(echo abcdef)

or even with a "here string":

{ gzip | wc -c; } <<<abcdef

Upvotes: 1

William Pursell
William Pursell

Reputation: 212248

It is probably easier to do:

$ s=abcdef
$ echo "$s" | gzip | wc -c

and then redefine s before repeating the command from your history. Or use a function:

$ foo() { echo "$*" | gzip | wc -c; }
$ foo abcdef

Upvotes: 1

Related Questions