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?


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.

  • 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).

  • 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
  • 3
    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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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