Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use curl in a shell script? [duplicate]

Tags:

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

#!/bin/bash
RVMHTTP="https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer"
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?

like image 636
san983 Avatar asked Nov 29 '11 22:11

san983


People also ask

Can we use curl command in shell script?

The curl command transfers data to or from a network server, using one of the supported protocols (HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, DICT, TELNET, LDAP or FILE). It is designed to work without user interaction, so it is ideal for use in a shell script.


2 Answers

#!/bin/bash                                                                                                                                                                                     
CURL='/usr/bin/curl'
RVMHTTP="https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer"
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

like image 70
Tilo Avatar answered Sep 25 '22 03:09

Tilo


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.

like image 27
ДМИТРИЙ МАЛИКОВ Avatar answered Sep 22 '22 03:09

ДМИТРИЙ МАЛИКОВ