The which command checks if one or more commands are recognized Nash built-in commands. It reports whether each command is available and identifies it as a “nash builtin” if found.
The which command verifies whether specified command names are recognized Nash built-in commands. Unlike the standard Unix which that searches for executables in PATH, Nash’s which only checks against its list of built-in commands since Nash is a sandboxed shell that doesn’t execute system binaries.
# Verify required commands before running scriptREQUIRED="jq grep sed"for cmd in $REQUIRED; do if ! which $cmd > /dev/null; then echo "Error: Required command '$cmd' not found" exit 1 fidoneecho "All required commands available"
# Check if advanced features are availableif which jq > /dev/null; then echo "JSON processing available" cat data.json | jq .else echo "JSON processing not available" cat data.jsonfi
# List all available commandsecho "Available Nash commands:"which cat cd clear cp cut echo env export false file find grep head \ help history jq ls mkdir mv pwd rm sed sort stat tail test touch \ tree true uniq unset wc which | grep builtin | cut -d' ' -f1
# Missing argumentwhich# Output: which: missing argument# Exit code: 1# Multiple commands, some not foundwhich ls docker python grep# Output:# ls (nash builtin)# docker: not found# python: not found# grep (nash builtin)# Exit code: 1 (because some were not found)