Super User is a question and answer site for computer enthusiasts and power users. 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

In addition to my own computer, I sometimes use an Ubuntu cluster at my school. Rather than manually keep my .bashrc's in sync, I would like to make the school cluster's .bashrc source my personal .bashrc from DropBox via a URL. However, when I naively try source http://myurl, I just get an error: http://myurl: No such file or directory. How can I can get bash to source from a script located online?

Worst case, I could curl to a named pipe and source that. Is there anything more elegant?

share|improve this question
up vote 6 down vote accepted

You can use process substitution with source:

source <(curl -s

Note: I consider directly running code retrieved over the internet to be a serious security risk. It's probably less risky if this is done over an internal network (depending on its overall security).

share|improve this answer
Clever! Good point though that an attacker could easily feed me any code they want. – AlcubierreDrive Mar 9 '11 at 14:49
Works on Linux, fails on OSX. Writing to a tempfile for OSX instead. – nilbus Sep 8 '14 at 20:29
@nilbus: According to this, you might try source <(curl -s | iconv -f windows-1251) – Dennis Williamson Sep 8 '14 at 20:57
That got rid of the error, but the script didn't run still on OSX. – nilbus Sep 9 '14 at 0:31
The part of this that jumps out at me is the fact that I can set a variable from^H^H^H^Hin the main script and call that variable without having to redeclare it in the sourced script. curl <file> | /bin/bash won't allow that without exporting the variables. – dafydd Dec 5 '15 at 4:32

Can't you just use

curl | bash 
share|improve this answer
That works and it's what I'm currently doing, but I was wondering if there's a more elegant way. But maybe this is the best, so if nothing turns up soon I'll accept your answer. – AlcubierreDrive Mar 9 '11 at 14:12
Also, note that this is going in my .bashrc, so technically your solution is infinite recursion. ;) But I know what you meant. – AlcubierreDrive Mar 9 '11 at 14:45
Piping commands to bash will execute them in a separate process, which makes this method unusable for executing bashrc. – grawity Mar 9 '11 at 15:15
Depends on what the commands are - but yes, sorry I agree – John Burton Mar 9 '11 at 16:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .