Linked Questions
123 questions linked to/from How can I check if a program exists from a Bash script?
229
votes
8
answers
202k
views
How can I check if a command exists in a shell script? [duplicate]
I am writing my first shell script. In my script I would like to check if a certain command exists, and if not, install the executable. How would I check if this command exists?
if # Check that ...
60
votes
7
answers
53k
views
Detect if executable file is on user's PATH [duplicate]
In a bash script, I need to determine whether an executable named foo is on the PATH.
66
votes
1
answer
61k
views
'which' vs 'command -v' in Bash [duplicate]
I've read in some bash FAQ a while ago (that I don't remember), that which should be avoided and command -v preferred.
Why is that so? What are the advantages, disadvantages of either one?
20
votes
2
answers
39k
views
How to check if Docker is installed in a Unix shell script? [duplicate]
I need to check in a shell script if Docker is installed (Ubuntu server).
I came up with this, but the syntax is not correct.
if [[ which docker && docker --version ]]; then
echo "Update ...
4
votes
1
answer
13k
views
Bash, ... check if a program is installed or not, using bash script [duplicate]
I am trying to create a little script that check if a program is installed or not. I am trying with tmux, ...
`tmux --help` | grep "tmux: command not found" &> /dev/null
if [ $? == 1 ]; then
...
0
votes
1
answer
5k
views
bash, test if curl exists, and install if it does not [duplicate]
I googled many solutions but did not find one that fully worked. My own rough working is:
[ $(which curl) -eq "" ] || sudo apt install curl
This doesn't quite work, saying "unary ...
0
votes
2
answers
5k
views
Bash: How to determine if a command exists without running it? [duplicate]
I'm using Bash on OS X. There are several commands that I want to determine if exist, but don't want to run them in case they do exist and have unwanted effects. For example, if I wanted to test if ...
0
votes
1
answer
1k
views
check if a program is already installed [duplicate]
I want to check whether a program like firefox exists on ubuntu or not. In case it is not installed, I want to install it. I studied this topic and got information about command -v p programName, but ...
1
vote
2
answers
168
views
What does `location=$(type -p "htop")` mean in a script? [duplicate]
The script is this
#!/bin/bash
echo
echo "################################################################"
echo " Installing Htop "
...
2
votes
0
answers
224
views
which fails to find command in path [duplicate]
I have a program called f in my $PATH, I can simply execute it by typing f into a terminal. However, typing which f into that same terminal afterwards, it errors out: which: no f in (...), and it ...
0
votes
0
answers
98
views
How to suppress Error printed by shell commands. [duplicate]
I am writing an Script(BASH script), which uses dpkg, rpm, pacman commands, but at a time for a os one command is applicable, these command will run in different OS so for some os dpkg will pop up the ...
1
vote
0
answers
92
views
Checking if package is installed [duplicate]
I am trying to build a bash script which ultimately runs a docker container. I am running Ubuntu 20.04 LTS on a VM.
Docker works perfectly and I can run the image I want to, but now I want to ...
0
votes
0
answers
62
views
How can I check if a command is valid in a bash script? [duplicate]
I haven't done much bash scripting in the past (this is probably only my fourth or fifth script I have created). The current script i'm making will repeat a command (the script's argument) until it ...
0
votes
0
answers
16
views
Shell executes command from different path to the one shown by which in RedHat6 [duplicate]
I've just noticed that when calling python from the command line, it just calls python from /usr/bin/python on account that it started v2.6:
$ python
Python 2.6.6 (r266:84292, Jun 11 2019, 11:01:44)
...
1190
votes
12
answers
800k
views
What does 'set -e' mean in a Bash script?
I'm studying the content of this preinst file that the script executes before that package is unpacked from its Debian archive (.deb) file.
The script has the following code:
#!/bin/bash
set -e
# ...