On Wed, Aug 17, 2022 at 10:58:17PM -0500, David Wright wrote: > $ type soxy > soxy is a function > soxy () > { > [ -z "$1" ] && printf '%s\n' "Usage: ${FUNCNAME[0]} > path-to/sound-file-of-any-type [trim 20 2] > runs sox to play the file with any arguments given. > The example above reminds you to put the full argument." 1>&2 && return > 1; > local From="$1"; > shift; > sox -q "$From" -t alsa default "$@" > }
Pedantic note: your error checking can fail. If the printf fails for some reason (e.g. because stderr has been closed, or is redirected to a file on a file system that's full), the return won't execute. It's best just to use "if" in the normal way: if [ -z "$1" ]; then printf ... return 1 fi That way, the return will still be executed even if the printf fails. If you *insist* on using && because you think it's tres chic or something, then you need to use a command group: [ -z "$1" ] && { printf ... return 1 } But this is not the recommended practice.