From 3a5aaa961ea25b024930b28fe3a510d6f6a0d509 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 5 May 2013 06:52:14 -0400 Subject: [PATCH] Convert `which` -> `command -v` for POSIX compliance I learned (via the Git list [1]) that `which` is not part of POSIX. The POSIX 2008 equivalent is `command -v` [2]. We can make the Bash-init scripts more portable by sticking to the POSIX utilities [3]. They'll also be slightly faster because `command` is a Bash builtin: $ command -V command command is a shell builtin [1]: http://article.gmane.org/gmane.comp.version-control.git/216007 [2]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html [3]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap04.html#tag_20 --- local-patch.examples/005-dotfiles-update-relative.patch | 2 +- src/.bash_profile | 2 +- src/.bashrc.d/05local_paths | 2 +- src/.bashrc.d/90dotfiles | 2 +- src/.xinitrc | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/local-patch.examples/005-dotfiles-update-relative.patch b/local-patch.examples/005-dotfiles-update-relative.patch index 8a346d3..1995d7b 100644 --- a/local-patch.examples/005-dotfiles-update-relative.patch +++ b/local-patch.examples/005-dotfiles-update-relative.patch @@ -2,7 +2,7 @@ +++ b/.bashrc.d/90dotfiles @@ -2,5 +2,5 @@ - DS="$(which dotfiles.sh)" + DS="$(command -v dotfiles.sh)" if [ -n "${DS}" ] && [ -f "${DS}" ] && [ -x "${DS}" ]; then - "${DS}" --dotfiles-dir ~/src/dotfiles update + "${DS}" --dotfiles-dir ~/src/dotfiles update --relative diff --git a/src/.bash_profile b/src/.bash_profile index 9e5da4b..cc0a755 100644 --- a/src/.bash_profile +++ b/src/.bash_profile @@ -21,7 +21,7 @@ fi # print my calendar if I've configured it # http://bsdcalendar.sourceforge.net/ (Gentoo: app-misc/calendar) -CALENDAR=$(which calendar 2> /dev/null) +CALENDAR=$(command -v calendar) if [ -n "${CALENDAR}" ] && [ -f ~/.calendar/calendar ]; then calendar fi diff --git a/src/.bashrc.d/05local_paths b/src/.bashrc.d/05local_paths index 5c99a34..447a92c 100644 --- a/src/.bashrc.d/05local_paths +++ b/src/.bashrc.d/05local_paths @@ -33,7 +33,7 @@ unset x # personalize Perl path #export PERL5LIB="${HOME}/lib/perl5/vendor_perl/5.12.2" -# personalize Java path (found by tracing from `which javac`) +# personalize Java path (found by tracing from `command -v javac`) #export JAVA_HOME=/usr/lib/jvm/java-6-openjdk/ # personalize ruby and rubygems paths diff --git a/src/.bashrc.d/90dotfiles b/src/.bashrc.d/90dotfiles index c4fcf06..69f310f 100644 --- a/src/.bashrc.d/90dotfiles +++ b/src/.bashrc.d/90dotfiles @@ -1,6 +1,6 @@ # Run the dotfiles.sh script if it exists -DS="$(which dotfiles.sh)" +DS="$(command -v dotfiles.sh)" if [ -n "${DS}" ] && [ -f "${DS}" ] && [ -x "${DS}" ]; then "${DS}" --dotfiles-dir ~/src/dotfiles update fi diff --git a/src/.xinitrc b/src/.xinitrc index 678fcc3..eb05cf7 100755 --- a/src/.xinitrc +++ b/src/.xinitrc @@ -2,7 +2,7 @@ # # .xinitrc, a startup file for X -if [ -n $(which conky) ]; then +if [ -n $(command -v conky) ]; then conky & fi @@ -15,7 +15,7 @@ if [ -e /usr/bin/asus_acpid ]; then fi # Set up keybindings -if [ -n $(which xmodmap) ]; then +if [ -n $(command -v xmodmap) ]; then xmodmap ~/.Xmodmap fi -- 2.26.2