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
+++ 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
# 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
# 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
# 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
#
# .xinitrc, a startup file for X
-if [ -n $(which conky) ]; then
+if [ -n $(command -v conky) ]; then
conky &
fi
fi
# Set up keybindings
-if [ -n $(which xmodmap) ]; then
+if [ -n $(command -v xmodmap) ]; then
xmodmap ~/.Xmodmap
fi