# command-p.sh: test of the command built-in for any POSIX-compliant shell posix="true" test_o 'redirection error on special built-in does not kill shell' command : <_no_such_file_ echo reached __IN__ reached __OUT__ test_o 'dot script not found does not kill shell' command . ./_no_such_file_ echo reached __IN__ reached __OUT__ test_o 'assignment on special built-in is temporary' a=a a=b command : echo $a __IN__ a __OUT__ test_OE -e n 'command ignores function (mandatory built-in)' false () { true; } command false __IN__ test_E -e 0 'command ignores function (substitutive built-in)' echo () { false; } command echo __IN__ test_OE -e 0 'command ignores function (external command)' cat () { false; } command cat foo chmod a+x foo test_x -e 0 'exit status of describing external command (-v, with slash)' command -v ./foo __IN__ test_x -e 0 'exit status of describing external command (-V, with slash)' command -V ./foo __IN__ test_E -e 0 'output of describing external command (-v, with slash)' command -v ./foo | grep '^/' | grep '/foo$' __IN__ test_E -e 0 'output of describing external command (-V, with slash)' command -V ./foo | grep -F "$(command -v ./foo)" __IN__ test_oE -e 0 'describing function (-v)' cat() { :; } command -v cat __IN__ cat __OUT__ test_E -e 0 'describing function (-V)' cat() { :; } command -V cat __IN__ test_oE -e 0 'describing alias (-v)' alias abc='echo ABC' command="$(command -v abc)" unalias abc eval "$command" abc __IN__ ABC __OUT__ test_OE -e 0 'describing alias (-V)' alias abc=xyz d="$(command -V abc)" case "$d" in (*abc*xyz*|*xyz*abc*) # expected output contains alias name and value ;; (*) printf '%s\n' "$d" # print non-conforming result ;; esac __IN__ test_OE -e n 'describing non-existent command (-v)' PATH= command -v _no_such_command_ __IN__ test_x -e n 'describing non-existent command (-V)' PATH= command -V _no_such_command_ __IN__ # TODO The -p option is not supported on some systems. case "$(uname)" in (Darwin) ;; (*) skip='true' ;; esac test_x -e 0 'describing external command with standard path (-v)' PATH= command -pv cat __IN__ test_x -e 0 'describing external command with standard path (-V)' PATH= command -pV cat __IN__ ) test_O -d -e 127 'executing non-existent command' command ./_no_such_command_ __IN__