3

I see a lot of installation instructions which ask you to download a file and run it straight away like this: wget https://some-site.com/some-file.sh | bash. However I would like to pipe the file through to less first so I can see the file before piping the file to bash. How can I do this in a one-liner?

3

Using vipe from moreutils. Demo with seq 20 instead of wget.

Run this:

seq 20 | EDITOR=less vipe | wc -l

...and less opens the pipe for viewing. Press q to quit less, and the line count from wc -l appears:

20

Now do the same:

seq 20 | EDITOR=less vipe | wc -l

...but this time, hit Ctrl-C, then q to quit less. Because of the Ctrl-C, wc never runs.

Therefore this should work:

wget -qO- https://some-site.com/some-file.sh | EDITOR=less vipe | bash 

And if the code doesn't please, hit Ctrl-C.

If you want to keep the file around despite maybe not wanting to run it, try this:

wget -qO- https://some-site.com/some-file.sh | tee /tmp/some-file.sh |
EDITOR=less vipe | bash 

...and it'll work much the same, except that /tmp/some-file.sh will have the pipe contents as well.

3
  1. Download the file.
  2. Look at it.
  3. Run it.
$ curl -O https://some/url/file.sh
$ less file.sh
$ bash file.sh

That would be easiest and most robust.

1

Within less, you can press s to save the input to a file.

Or g to get to the top and then |$bash to pipe to bash.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy