Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

I have a file, f, on my webserver with the following contents:

alias ll='ls -l'

I would like to (from another linux box) do the following, but I can't get the command right:

curl http://myserver/f | ?

Where the ? will read each line into the current environment. So, given the above file, this would have the same effect as doing

% alias ll='ls -l'

in the current shell process. Is this possible?

share|improve this question
up vote 3 down vote accepted

How about using eval "$(curl "$URL")"?

But you better be really sure you get the right URL, and the downloaded code doesn't do anything nasty.

share|improve this answer
gets the nod for brevity. Cautions re: eval duly noted. – g33kz0r Jul 15 '11 at 14:37

In Bash you could try sourcing /dev/stdin after redirecting the output of the curl command to /dev/stdin in a single line like so:

source /dev/stdin  <<< "$(curl http://myserver/f)"

This should avoid (sourced) variable assignment in a subshell (which would be invisible by the parent shell).

share|improve this answer
This works in Bash and zsh. I like it – g33kz0r Jul 15 '11 at 14:32

To avoid nasty issues with eval, you could just save it to file and then source it:

curl -O f http://myserver/f
chmod u+x f
. f
share|improve this answer
There is no issue with eval that sourcing a file doesn't have. Using an intermediate file gives you the opportunity to perform additional validation, or not re-download the file if it's already there, but if you're not doing any of this there's no benefit to not using eval. – Gilles Jul 14 '11 at 10:05
@Gilles, you're right. I'd never thought that eval "$(cat test.sh)" and . test.sh would produce the exact same result, but that seems indeed to be the case. Makes sense... – l0b0 Jul 14 '11 at 12:38

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.