command line: pipe vs redirect

2020-07-28

 | 

~1 min read

 | 

141 words

Recently, I was trying to use the LastPass CLI to generate a password. Because I’m lazy, I wanted the new password to go directly to my clipboard so I could paste it where I needed it.

Remembering my previous post on generating an ssh key (ssh keygen basics), I started with:

pbcopy < lpass generate 30 new-pass

This threw an error, however because the output of lpass gen is not a file with that password, but simply a STDOUT. The < however is expecting to take in a file’s contents.

The answer then, was not to use a redirect (of the file’s contents into pbcopy), but to pipe those contents to pbcopy as its first argument.

lpass generate 30 new-pass | pbcopy

Making this mistake really helped me clarify the difference between the redirect and the pipe!



Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!