Passing Flags to a Piped Script [duplicate] - bash

This question already has answers here:
Pass args for script when going thru pipe
(3 answers)
Closed 9 months ago.
I have written a shell script to configure a development environment and and retrieving using cURL. The script takes up to 3 flags, -d, -f and -s.
How do I pass the flags to the shell script?
Here is the command to run the bash script:
$ curl -sL https://example.com/setup.sh | bash
Here is my first (failed) attempt to pass flags to the script:
$ curl -sL https://example.com/setup.sh | bash -dfs
bash: -d: invalid option
Can anyone explain how to do this?

Use the -s argument:
curl -sL https://example.com/setup.sh | bash -s -- -dfs

Related

How can I add arguments to a piped script in fish shell?

I am looking for a way to add arguments to a piped curl script which shall be executed in a fish shell. In my case, this is installation of oh-my-fish via curl.
The command without arguments is:
curl https://raw.githubusercontent.com/oh-my-fish/oh-my-fish/master/bin/install | fish
But as I want to run this in a non interactive environment, I want to add the arguments --noninteractive and --yes to the downloaded script to get something like
curl https://raw.githubusercontent.com/oh-my-fish/oh-my-fish/master/bin/install | fish -- --noninteractive --yes
This code is just to express, what I want and does not run.
For bash the equivalent would be
curl https://raw.githubusercontent.com/oh-my-fish/oh-my-fish/master/bin/install | bash -s -- --noninteractive --yes
but I cannot find a way to do this with fish.
Tell fish to source stdin with arguments explicitly:
curl | fish -c 'source - --noninteractive --yes'
The - as the filename stands for stdin, any further arguments to source will be used as the $argv, no -- is necessary.
Alternatively, separate the download and running step:
curl > file
fish file --noninteractive --yes
Fish stops processing its own arguments after the filename so, again, no -- necessary.
Or, for your problem at hand, oh-my-fish reads the variables "NONINTERACTIVE" and "ASSUME_YES", so you can do
curl | NONINTERACTIVE=1 ASSUME_YES=1 fish

bash script does not execute lines after sudo, no errors [duplicate]

This question already has answers here:
Pass commands as input to another command (su, ssh, sh, etc)
(3 answers)
Why can't I use 'sudo su' within a shell script? How to make a shell script run with sudo automatically
(6 answers)
how to execute multiple commands after sudo command
(2 answers)
Closed 5 years ago.
I have a little bash script to run, but it appears to stop without errors on the second line:
export REQUIRE_TRIGGER=0
sudo -s -H
killall ptpd ntpd
nice -n -19 ptpd -gGW -b eth0 -s2 -i NTP -t -c D
The script is in a file. What am I missing?
try to do
sudo killall ptpd ntpd
sudo nice -n -19 ptpd -gGW -b eth0 -s2 -i NTP -t -c D

What is | bash -

What exactly does | bash - at the end of the first line of this code do in a Dockerfile?
Why the - at the end?
RUN curl --silent --location https://rpm.nodesource.com/setup_4.x | bash -
RUN yum install -y tar nodejs
The | bash means to pipe the output from the curl command, i.e. the downloaded bash script, as input to the bash command. The - makes bash read the script from stdin instead of from a file.
In other words, the command downloads a script and executes it with bash.

Pass parameters to bash script fetched via curl

This is a question looking for a different syntax aside from the following three:
curl https://sdk.cloud.google.com | bash -s arg1 arg2
curl https://sdk.cloud.google.com | bash /dev/stdin arg1 arg2
bash <( curl https://sdk.cloud.google.com ) arg1 arg2
for passing arguments to a script fetched via curl ... because none of the ones listed work with the gcloud script that I'm trying to install silently onto a VM.
I've already looked into these but didn't find a 4th alternative to try out:
passing arguments to an interactive program non interactively
passing parameters to bash when executing a script fetched by curl
Execute bash script from URL
Circling back, turns out to be a very niche answer, as folks from google support provided this syntax:
export CLOUDSDK_CORE_DISABLE_PROMPTS=1; curl -s https://sdk.cloud.google.com | bash &>/tmp/gcloud_install_$(date +%Y%m%d%H%M).log

What does it mean when a shell command starts with \ [duplicate]

This question already has answers here:
Why start a shell command with a backslash?
(2 answers)
Closed 8 years ago.
I found these command from http://rvm.io/rvm/install
Why do we need \ in the following command?
$\curl -sSL https://get.rvm.io | bash
Short version: This skips replacing "curl" with an alias you might have defined.
A more verbose answer you can find here: \curl ... | bash ... what's the slash for?

Resources