Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is slightly messy to explain.

I have a script that I want to deploy like this:

curl -Ls | bash

The trouble is the script reads from standard input like so:

echo "You should edit /srv/pillar/tm.sls now. Comments are in the file."
echo Type "skip" to skip or anything else to edit.
read text
if [ "$text" != "skip" ]; then
sudo pico /srv/pillar/tm.sls

Now, since stdin is obviously serving as the source of the script itself, this doesn't currently work. Is there a way I can regain the terminal?

(The current workaround is to deploy it like this: curl -Ls > && bash

share|improve this question
don't force users to use pico. use editor=${VISUAL:-$EDITOR}; sudo "${editor:-pico}" file – glenn jackman Feb 19 '14 at 14:26
Thanks for the tip - I looked for a variable like that, but neither VISUAL nor EDITOR were set. Also didn't know about {$VAR:-default} substitution, thanks again. – Steve Bennett Feb 19 '14 at 22:40
up vote 2 down vote accepted

Use a process substitution

bash <(curl -Ls
share|improve this answer
Thanks - I still don't understand from the Gnu page how that's different from piping, but it does work. It's better than my current workaround, but I was still hoping for a way in the form curl ... | bash, because I think that's what people expect. – Steve Bennett Feb 19 '14 at 22:47
@SteveBennett this is different from piping in that this invokes bash filename where filename is the name of the FIFO to which the curl process writes its output. Piping is not possible by definition: it connects a stream to bash's stdin. – zwets Feb 20 '14 at 9:59
Piping has a side-effect: the components of a pipeline are executed in subshells. The difficulty is seen in something like this: seq 10 | while read num; do ((sum+=num)); done; echo $sum -- $sum is blank because the while loop is executed in a subshell, and all the modifications to the "sum" variable disappear when the subshell exits. – glenn jackman Feb 20 '14 at 12:10
Yeah, thanks. Interesting that I've never seen this technique before! – Steve Bennett Feb 21 '14 at 0:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.