Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash's source command not working with a file curl'd from internet

Tags:

bash

shell

url

I am trying to source a script file from the internet using curl, like this: source <( curl url ); echo done , and what I see is that 'done' is echoed before the curl even starts to download the file!

Here's the actual command and the output:

-bash-3.2# source <( curl --insecure https://raw.github.com/gurjeet/pg_dev_env/master/.bashrc ) ; echo done
done
-bash-3.2# % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2833 100 2833 0 0 6746 0 --:--:-- --:--:-- --:--:-- 0

I am not too worried about 'done' being echoed before or after anything, I am particularly concerned why the source command wouldn't read and act on the script!

This command works as expected on my LinuxMint's bash, but not on the CentOS server's bash!

like image 767
Gurjeet Singh Avatar asked May 09 '12 16:05

Gurjeet Singh


People also ask

Why is my curl command not working?

We might have come across errors like “curl: command not found” while working in the terminal. This type of error comes due to only one reason: the relevant package is not installed. Curl is a very popular data transfer command-line utility used for downloading and uploading data from or to the server.


1 Answers

At first, I failed to notice that you're using Bash 3.2. That version won't source from a process substitution, but later versions such as Bash 4 do.

You can save the file and do a normal source of it:

source /tmp/del

(to use the file from your comment)

Or, you can use /dev/stdin and a here-string and a quoted command substitution:

source /dev/stdin <<< "$(curl --insecure https://raw.github.com/gurjeet/pg_dev_env/master/.bashrc)"; echo done
like image 68
Dennis Williamson Avatar answered Oct 18 '22 11:10

Dennis Williamson