Convert `which` -> `command -v` for POSIX compliance
authorW. Trevor King <wking@tremily.us>
Sun, 5 May 2013 10:52:14 +0000 (06:52 -0400)
committerW. Trevor King <wking@tremily.us>
Sun, 5 May 2013 10:52:14 +0000 (06:52 -0400)
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
src/.bash_profile
src/.bashrc.d/05local_paths
src/.bashrc.d/90dotfiles
src/.xinitrc

index 8a346d3f2fdd4d26e2d0573d85e85c78d0ea000c..1995d7bc1e515ef135e467df73885efe575d89b0 100644 (file)
@@ -2,7 +2,7 @@
 +++ b/.bashrc.d/90dotfiles
 @@ -2,5 +2,5 @@
  
 +++ 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
  if [ -n "${DS}" ] && [ -f "${DS}" ] && [ -x "${DS}" ]; then
 -      "${DS}" --dotfiles-dir ~/src/dotfiles update
 +      "${DS}" --dotfiles-dir ~/src/dotfiles update --relative
index 9e5da4b2b247d26017da823c8e7aeef06a128a58..cc0a755e02dc4654ff10d0d4f00d641ff69b83b1 100644 (file)
@@ -21,7 +21,7 @@ fi
 
 # print my calendar if I've configured it
 # http://bsdcalendar.sourceforge.net/  (Gentoo: app-misc/calendar)
 
 # 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
 if [ -n "${CALENDAR}" ] && [ -f ~/.calendar/calendar ]; then
     calendar
 fi
index 5c99a3472138a473d94a73eaced74b82797ca519..447a92c11ac1bd554e59a58e73224c0d6572726c 100644 (file)
@@ -33,7 +33,7 @@ unset x
 # personalize Perl path
 #export PERL5LIB="${HOME}/lib/perl5/vendor_perl/5.12.2"
 
 # 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
 #export JAVA_HOME=/usr/lib/jvm/java-6-openjdk/
 
 # personalize ruby and rubygems paths
index c4fcf06eb33868cb6ff3f92098d5ae0fcecc665c..69f310f802dd803b596d58cd3356eeb3c5f95688 100644 (file)
@@ -1,6 +1,6 @@
 # Run the dotfiles.sh script if it exists
 
 # 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
 if [ -n "${DS}" ] && [ -f "${DS}" ] && [ -x "${DS}" ]; then
        "${DS}" --dotfiles-dir ~/src/dotfiles update
 fi
index 678fcc32f3133c0b944fa15d685d24d721da8d2f..eb05cf7d61dab6effcc6b6bdbc2426ed5ebb29af 100755 (executable)
@@ -2,7 +2,7 @@
 #
 # .xinitrc, a startup file for X
 
 #
 # .xinitrc, a startup file for X
 
-if [ -n $(which conky) ]; then
+if [ -n $(command -v conky) ]; then
     conky &
 fi
 
     conky &
 fi
 
@@ -15,7 +15,7 @@ if [ -e /usr/bin/asus_acpid ]; then
 fi
 
 # Set up keybindings
 fi
 
 # Set up keybindings
-if [ -n $(which xmodmap) ]; then
+if [ -n $(command -v xmodmap) ]; then
        xmodmap ~/.Xmodmap
 fi
 
        xmodmap ~/.Xmodmap
 fi