How to Use Curl in a Shell Script? [Duplicate]

How to Use Curl in a Shell Script? [Duplicate]

I'm trying to run this shell script in order to install RVM in an Ubuntu box

#!/bin/bash
RVMHTTP=""
CURLARGS="-f -s -S -k"

bash < <(curl $CURLARGS $RVMHTTP)

but I get the following error

Syntax error: Redirection unexpected

Also tested not using the variables, but same result, could you tell what I'm missing?

4

3 Answers

#!/bin/bash                                                                                                                                                                                     
CURL='/usr/bin/curl'
RVMHTTP=""
CURLARGS="-f -s -S -k"

# you can store the result in a variable
raw="$($CURL $CURLARGS $RVMHTTP)"

# or you can redirect it into a file:
$CURL $CURLARGS $RVMHTTP > /tmp/rvm-installer

or:

Execute bash script from URL

url=”
content=”$(curl -sLI “$url” | grep HTTP/1.1 | tail -1 | awk {‘print $2′})”
if [ ! -z $content ] && [ $content -eq 200 ]
then
echo “valid url”
else
echo “invalid url”
fi

Firstly, your example is looking quite correct and works well on my machine. You may go another way.

curl $CURLARGS $RVMHTTP > ./install.sh

All output now storing in ./install.sh file, which you can edit and execute.

0
Sophia Al-Mansoor
Author

Sophia Al-Mansoor

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.