Re: question about sound
On Fri 19 Aug 2022 at 08:46:29 (-0400), Greg Wooledge wrote:
> On Thu, Aug 18, 2022 at 11:13:11PM -0500, David Wright wrote:
> > The attraction of a one-liner is partly because of screens
> > being around four times wider than high (characterwise).
> > Wouldn't it be nice if bash had Perl's die ….
>
> Some people put a die() function in their scripts, and then use it.
>
> die() { printf >&2 '%s\n' "$*"; exit 1; }
>
> Or variants thereof. There are almost as many variations as there are
> shell programmers.
But if I have that, and:
soxy is a function
soxy ()
{
[ -z "$1" ] && die "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.";
local From="$1";
shift;
sox -q "$From" -t alsa default "$@"
}
then typing just:
$ soxy
into an xterm will have the same effect as:
$ ^D
killing bash and the xterm, whereas what I would want from die is a
"double-return", quitting both die and soxy, and leaving me at:
$
just as Perl's die would do (if soxy was a Perl program).
On Fri 19 Aug 2022 at 22:53:24 (+1000), David wrote:
> If you want to stay close to the oneliner style that you already
> have, it could be done like this:
>
> die() {
> printf '%s\n' "$@" 1>&2
> return 0
> }
>
> soxy() {
> [[ -z "$1" ]] && die "message" && return 1
> }
I think that's the best we can do, unless I'm missing something.
Cheers,
David.
Reply to: