Execute 2 or more remote scripts sharing the same curl pattern, without redundancy

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I use Ubuntu 16.04 and I execute a list of remote scripts that are in the same directory (a GitHub repository):
curl -s https://raw.githubusercontent.com/$user/$repo/master/1.sh | tr -d 'r' | bash
curl -s https://raw.githubusercontent.com/$user/$repo/master/2.sh | tr -d 'r' | bash
curl -s https://raw.githubusercontent.com/$user/$repo/master/3.sh | tr -d 'r' | bash
curl -s https://raw.githubusercontent.com/$user/$repo/master/4.sh | tr -d 'r' | bash
curl -s https://raw.githubusercontent.com/$user/$repo/master/5.sh | tr -d 'r' | bash
curl -s https://raw.githubusercontent.com/$user/$repo/master/6.sh | tr -d 'r' | bash
How would you cope with the awful redundancy?
I think of a for loop but I have no idea how to construct it. All for loops I've seen so far doesn't give me a clue on how to do that particular task of reusing a curl pattern (and piped output) for different files in the same remote directory.
You are more than welcome to share an example.
Update
- There might be more or less than six such
curloperations. - I would use any plausible way but if it requires a utility please recommend a utility available in the Debian repositories.
shell-script pipe wildcards curl for
add a comment |Â
up vote
1
down vote
favorite
I use Ubuntu 16.04 and I execute a list of remote scripts that are in the same directory (a GitHub repository):
curl -s https://raw.githubusercontent.com/$user/$repo/master/1.sh | tr -d 'r' | bash
curl -s https://raw.githubusercontent.com/$user/$repo/master/2.sh | tr -d 'r' | bash
curl -s https://raw.githubusercontent.com/$user/$repo/master/3.sh | tr -d 'r' | bash
curl -s https://raw.githubusercontent.com/$user/$repo/master/4.sh | tr -d 'r' | bash
curl -s https://raw.githubusercontent.com/$user/$repo/master/5.sh | tr -d 'r' | bash
curl -s https://raw.githubusercontent.com/$user/$repo/master/6.sh | tr -d 'r' | bash
How would you cope with the awful redundancy?
I think of a for loop but I have no idea how to construct it. All for loops I've seen so far doesn't give me a clue on how to do that particular task of reusing a curl pattern (and piped output) for different files in the same remote directory.
You are more than welcome to share an example.
Update
- There might be more or less than six such
curloperations. - I would use any plausible way but if it requires a utility please recommend a utility available in the Debian repositories.
shell-script pipe wildcards curl for
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I use Ubuntu 16.04 and I execute a list of remote scripts that are in the same directory (a GitHub repository):
curl -s https://raw.githubusercontent.com/$user/$repo/master/1.sh | tr -d 'r' | bash
curl -s https://raw.githubusercontent.com/$user/$repo/master/2.sh | tr -d 'r' | bash
curl -s https://raw.githubusercontent.com/$user/$repo/master/3.sh | tr -d 'r' | bash
curl -s https://raw.githubusercontent.com/$user/$repo/master/4.sh | tr -d 'r' | bash
curl -s https://raw.githubusercontent.com/$user/$repo/master/5.sh | tr -d 'r' | bash
curl -s https://raw.githubusercontent.com/$user/$repo/master/6.sh | tr -d 'r' | bash
How would you cope with the awful redundancy?
I think of a for loop but I have no idea how to construct it. All for loops I've seen so far doesn't give me a clue on how to do that particular task of reusing a curl pattern (and piped output) for different files in the same remote directory.
You are more than welcome to share an example.
Update
- There might be more or less than six such
curloperations. - I would use any plausible way but if it requires a utility please recommend a utility available in the Debian repositories.
shell-script pipe wildcards curl for
I use Ubuntu 16.04 and I execute a list of remote scripts that are in the same directory (a GitHub repository):
curl -s https://raw.githubusercontent.com/$user/$repo/master/1.sh | tr -d 'r' | bash
curl -s https://raw.githubusercontent.com/$user/$repo/master/2.sh | tr -d 'r' | bash
curl -s https://raw.githubusercontent.com/$user/$repo/master/3.sh | tr -d 'r' | bash
curl -s https://raw.githubusercontent.com/$user/$repo/master/4.sh | tr -d 'r' | bash
curl -s https://raw.githubusercontent.com/$user/$repo/master/5.sh | tr -d 'r' | bash
curl -s https://raw.githubusercontent.com/$user/$repo/master/6.sh | tr -d 'r' | bash
How would you cope with the awful redundancy?
I think of a for loop but I have no idea how to construct it. All for loops I've seen so far doesn't give me a clue on how to do that particular task of reusing a curl pattern (and piped output) for different files in the same remote directory.
You are more than welcome to share an example.
Update
- There might be more or less than six such
curloperations. - I would use any plausible way but if it requires a utility please recommend a utility available in the Debian repositories.
shell-script pipe wildcards curl for
edited Feb 9 at 17:45
asked Feb 9 at 12:11
user9303970
123224
123224
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
4
down vote
accepted
For two or more files you could use Unix seq:
for var in $(seq 6)
do
curl -s https://raw.githubusercontent.com/$user/$repo/master/$var.sh | tr -d 'r' | bash
done
Explanation:
- Use the output of
seqto attain a count up to 6 (as the question lists 6curloperations). - Read the output into the variable
varand use this in yourcurlcommand.
1
double quote your variables when you use them -$useror$repocould contain spaces, tabs, or shell metacharacters. In this case, just double-quote the entire URL string:curl -s "https://raw.githubusercontent.com/$user/$repo/master/$var.sh" | tr ...
â cas
Feb 9 at 13:52
Is theseq 6an upper border? I could put it to say 10 if I had a range of 1-10 files?
â user9303970
Feb 9 at 15:05
Yes, you can change it to what ever you want
â Raman Sailopal
Feb 9 at 15:32
Sure, just wanted to ensure it's a matter of range and not fixed number. Thanks!
â user9303970
Feb 9 at 16:48
add a comment |Â
up vote
3
down vote
The fastest one with GNU parallel:
parallel -j0 -k "curl -s https://raw.githubusercontent.com/$user/$repo/master/1.sh
| tr -d 'r' | bash" ::: 1..6
You may also specify the crucial number via dynamic variable:
n=7
parallel -j0 -k "curl -s https://raw.githubusercontent.com/$user/$repo/master/1.sh
| tr -d 'r' | bash" ::: $(seq $n)
https://www.gnu.org/software/parallel/man.html
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
For two or more files you could use Unix seq:
for var in $(seq 6)
do
curl -s https://raw.githubusercontent.com/$user/$repo/master/$var.sh | tr -d 'r' | bash
done
Explanation:
- Use the output of
seqto attain a count up to 6 (as the question lists 6curloperations). - Read the output into the variable
varand use this in yourcurlcommand.
1
double quote your variables when you use them -$useror$repocould contain spaces, tabs, or shell metacharacters. In this case, just double-quote the entire URL string:curl -s "https://raw.githubusercontent.com/$user/$repo/master/$var.sh" | tr ...
â cas
Feb 9 at 13:52
Is theseq 6an upper border? I could put it to say 10 if I had a range of 1-10 files?
â user9303970
Feb 9 at 15:05
Yes, you can change it to what ever you want
â Raman Sailopal
Feb 9 at 15:32
Sure, just wanted to ensure it's a matter of range and not fixed number. Thanks!
â user9303970
Feb 9 at 16:48
add a comment |Â
up vote
4
down vote
accepted
For two or more files you could use Unix seq:
for var in $(seq 6)
do
curl -s https://raw.githubusercontent.com/$user/$repo/master/$var.sh | tr -d 'r' | bash
done
Explanation:
- Use the output of
seqto attain a count up to 6 (as the question lists 6curloperations). - Read the output into the variable
varand use this in yourcurlcommand.
1
double quote your variables when you use them -$useror$repocould contain spaces, tabs, or shell metacharacters. In this case, just double-quote the entire URL string:curl -s "https://raw.githubusercontent.com/$user/$repo/master/$var.sh" | tr ...
â cas
Feb 9 at 13:52
Is theseq 6an upper border? I could put it to say 10 if I had a range of 1-10 files?
â user9303970
Feb 9 at 15:05
Yes, you can change it to what ever you want
â Raman Sailopal
Feb 9 at 15:32
Sure, just wanted to ensure it's a matter of range and not fixed number. Thanks!
â user9303970
Feb 9 at 16:48
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
For two or more files you could use Unix seq:
for var in $(seq 6)
do
curl -s https://raw.githubusercontent.com/$user/$repo/master/$var.sh | tr -d 'r' | bash
done
Explanation:
- Use the output of
seqto attain a count up to 6 (as the question lists 6curloperations). - Read the output into the variable
varand use this in yourcurlcommand.
For two or more files you could use Unix seq:
for var in $(seq 6)
do
curl -s https://raw.githubusercontent.com/$user/$repo/master/$var.sh | tr -d 'r' | bash
done
Explanation:
- Use the output of
seqto attain a count up to 6 (as the question lists 6curloperations). - Read the output into the variable
varand use this in yourcurlcommand.
edited Feb 9 at 17:54
Communityâ¦
1
1
answered Feb 9 at 12:29
Raman Sailopal
1,18117
1,18117
1
double quote your variables when you use them -$useror$repocould contain spaces, tabs, or shell metacharacters. In this case, just double-quote the entire URL string:curl -s "https://raw.githubusercontent.com/$user/$repo/master/$var.sh" | tr ...
â cas
Feb 9 at 13:52
Is theseq 6an upper border? I could put it to say 10 if I had a range of 1-10 files?
â user9303970
Feb 9 at 15:05
Yes, you can change it to what ever you want
â Raman Sailopal
Feb 9 at 15:32
Sure, just wanted to ensure it's a matter of range and not fixed number. Thanks!
â user9303970
Feb 9 at 16:48
add a comment |Â
1
double quote your variables when you use them -$useror$repocould contain spaces, tabs, or shell metacharacters. In this case, just double-quote the entire URL string:curl -s "https://raw.githubusercontent.com/$user/$repo/master/$var.sh" | tr ...
â cas
Feb 9 at 13:52
Is theseq 6an upper border? I could put it to say 10 if I had a range of 1-10 files?
â user9303970
Feb 9 at 15:05
Yes, you can change it to what ever you want
â Raman Sailopal
Feb 9 at 15:32
Sure, just wanted to ensure it's a matter of range and not fixed number. Thanks!
â user9303970
Feb 9 at 16:48
1
1
double quote your variables when you use them -
$user or $repo could contain spaces, tabs, or shell metacharacters. In this case, just double-quote the entire URL string: curl -s "https://raw.githubusercontent.com/$user/$repo/master/$var.sh" | tr ...â cas
Feb 9 at 13:52
double quote your variables when you use them -
$user or $repo could contain spaces, tabs, or shell metacharacters. In this case, just double-quote the entire URL string: curl -s "https://raw.githubusercontent.com/$user/$repo/master/$var.sh" | tr ...â cas
Feb 9 at 13:52
Is the
seq 6 an upper border? I could put it to say 10 if I had a range of 1-10 files?â user9303970
Feb 9 at 15:05
Is the
seq 6 an upper border? I could put it to say 10 if I had a range of 1-10 files?â user9303970
Feb 9 at 15:05
Yes, you can change it to what ever you want
â Raman Sailopal
Feb 9 at 15:32
Yes, you can change it to what ever you want
â Raman Sailopal
Feb 9 at 15:32
Sure, just wanted to ensure it's a matter of range and not fixed number. Thanks!
â user9303970
Feb 9 at 16:48
Sure, just wanted to ensure it's a matter of range and not fixed number. Thanks!
â user9303970
Feb 9 at 16:48
add a comment |Â
up vote
3
down vote
The fastest one with GNU parallel:
parallel -j0 -k "curl -s https://raw.githubusercontent.com/$user/$repo/master/1.sh
| tr -d 'r' | bash" ::: 1..6
You may also specify the crucial number via dynamic variable:
n=7
parallel -j0 -k "curl -s https://raw.githubusercontent.com/$user/$repo/master/1.sh
| tr -d 'r' | bash" ::: $(seq $n)
https://www.gnu.org/software/parallel/man.html
add a comment |Â
up vote
3
down vote
The fastest one with GNU parallel:
parallel -j0 -k "curl -s https://raw.githubusercontent.com/$user/$repo/master/1.sh
| tr -d 'r' | bash" ::: 1..6
You may also specify the crucial number via dynamic variable:
n=7
parallel -j0 -k "curl -s https://raw.githubusercontent.com/$user/$repo/master/1.sh
| tr -d 'r' | bash" ::: $(seq $n)
https://www.gnu.org/software/parallel/man.html
add a comment |Â
up vote
3
down vote
up vote
3
down vote
The fastest one with GNU parallel:
parallel -j0 -k "curl -s https://raw.githubusercontent.com/$user/$repo/master/1.sh
| tr -d 'r' | bash" ::: 1..6
You may also specify the crucial number via dynamic variable:
n=7
parallel -j0 -k "curl -s https://raw.githubusercontent.com/$user/$repo/master/1.sh
| tr -d 'r' | bash" ::: $(seq $n)
https://www.gnu.org/software/parallel/man.html
The fastest one with GNU parallel:
parallel -j0 -k "curl -s https://raw.githubusercontent.com/$user/$repo/master/1.sh
| tr -d 'r' | bash" ::: 1..6
You may also specify the crucial number via dynamic variable:
n=7
parallel -j0 -k "curl -s https://raw.githubusercontent.com/$user/$repo/master/1.sh
| tr -d 'r' | bash" ::: $(seq $n)
https://www.gnu.org/software/parallel/man.html
edited Feb 9 at 12:57
answered Feb 9 at 12:38
RomanPerekhrest
22.4k12144
22.4k12144
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f423029%2fexecute-2-or-more-remote-scripts-sharing-the-same-curl-pattern-without-redundan%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password