Use "command -v" instead of "which" in bash scripts

shellcheck recently added SC2330 checking for this. "which" is non-standard, and
not guaranteed by POSIX to have a meaningful exit status, while "command -v" is
specified by POSIX: https://stackoverflow.com/q/592620
This commit is contained in:
Florian Bruhin 2018-02-27 06:23:00 +01:00
parent 53fb5af99c
commit bc3e1b316d
2 changed files with 2 additions and 2 deletions

View File

@ -52,7 +52,7 @@ die() {
if ! [ -d "$DOWNLOAD_DIR" ] ; then
die "Download directory »$DOWNLOAD_DIR« not found!"
fi
if ! which "${ROFI_CMD}" > /dev/null ; then
if ! command -v "${ROFI_CMD}" > /dev/null ; then
die "Rofi command »${ROFI_CMD}« not found in PATH!"
fi

View File

@ -220,7 +220,7 @@ user_pattern='^(user|username|login): '
GPG_OPTS=( "--quiet" "--yes" "--compress-algo=none" "--no-encrypt-to" )
GPG="gpg"
export GPG_TTY="${GPG_TTY:-$(tty 2>/dev/null)}"
which gpg2 &>/dev/null && GPG="gpg2"
command -v gpg2 &>/dev/null && GPG="gpg2"
[[ -n $GPG_AGENT_INFO || $GPG == "gpg2" ]] && GPG_OPTS+=( "--batch" "--use-agent" )
pass_backend() {