This question already has answers here:
How can I suppress all output from a command using Bash?
(8 answers)
Closed 3 years ago.
I tried docker container rm container-name > /dev/null but this still prints Error: No such container: container-name. I'm trying to silence this error in my bash script.
Send stderr to /dev/null:
docker container rm container-name 2> /dev/null
Related
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
This question already has answers here:
Cannot use process substitution during docker build because bash goes into posix mode
(2 answers)
Closed 1 year ago.
I've create a simple vim distro and I install it manually in my local computer or inside a docker using a command like the following:
bash <(wget -qO- https://raw.githubusercontent.com/sensorario/newdots/master/install.sh)
This script works. But I want to execute it also inside a Dockerfile. Trying to simply add:
RUN bash <(wget -qO- https://raw.githubusercontent.com/sensorario/newdots/master/install.sh)
I got
=> ERROR [ 9/10] RUN bash <(wget -qO- https://raw.githubusercontent.com/sensorario/newdots/master/install.sh) 0.3s
------
> [ 9/10] RUN bash <(wget -qO- https://raw.githubusercontent.com/sensorario/newdots/master/install.sh):
#12 0.321 /bin/sh: 1: Syntax error: "(" unexpected
------
executor failed running [/bin/sh -c bash <(wget -qO- https://raw.githubusercontent.com/sensorario/newdots/master/install.sh)]: exit code: 2
ERROR: Service 'php' failed to build : Build failed
make: *** [recreate] Error 1
Then I though to add \ before (.
RUN bash <\(wget -qO- https://raw.githubusercontent.com/sensorario/newdots/master/install.sh\)
The new error is
=> ERROR [ 9/10] RUN bash <(wget -qO- https://raw.githubusercontent.com/sensorario/newdots/master/install.sh) 0.3s
------
> [ 9/10] RUN bash <(wget -qO- https://raw.githubusercontent.com/sensorario/newdots/master/install.sh):
#12 0.310 /bin/sh: 1: cannot open (wget: No such file
Other question (and answer) in stackoverflow does not helping me.
RUN executes the command using sh, but process substitution with <( is a bash extension.
Use an ordinary pipe
RUN wget -qO- https://raw.githubusercontent.com/sensorario/newdots/master/install.sh | bash
You could write instead:
RUN wget -qO- https://raw.githubusercontent.com/sensorario/newdots/master/install.sh | bash
Which doesn't require any bash-isms to work.
This question already has an answer here:
Makefile runs differently than shell command? (when using cat)
(1 answer)
Closed 1 year ago.
this is in my makefile:
docker-rm:
docker rm $(docker ps -aq)
and when I run it, I get this:
$ make docker-rm
docker rm
"docker rm" requires at least 1 argument.
See 'docker rm --help'.
Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...]
Remove one or more containers
make: *** [Makefile:15: docker-rm] Błąd 1
It is not that I have no containers to remove, because when I run docker command without makefile it works fine:
$ docker rm $(docker ps -aq)
463323e2bcf0
eef08f265387
2152910c6fe6
d7e7e9aff4e2
82875b1966c9
2d9295c8d32d
b9a45885e45d
You have to quote $ in Makefile's.
docker-rm:
docker rm $$(docker ps -aq)
This question already has answers here:
Propagate all arguments in a Bash shell script
(12 answers)
Closed 2 years ago.
I'm trying to use all arguments from my function like this
function docker_run {
docker run \
-it --rm \
--entrypoint "" \
--volume "$(pwd):/${repo}" \
--workdir "/${repo}" \
alpine/git:v2.26.2 \
"$*"
}
docker_run sh -c "git reset && git add --a && git status"
this gives the error:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: "sh -c git reset && git add --a && git status": executable file not found in $PATH": unknown.
if I remove quotes around $* the error is:
usage: git [--version] [--help] [-C ]...
is *$ the correct variable to use? ideally I'd want docker_run to work with any possible argument combination
If you want to use all arguments, you should use $# and not $*. $# is special in that it's array-like, so when you put it in quotes it expands to all arguments. $* is a string that joins the arguments with spaces, so it globs into one argument.
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