Run shell script text failing silently

I am trying to run a simple script to make an mp3 of the currently selected wav file using Lame.

The script works fine until the actual part where it does the work.

I currently have the following:

mp3=$(cat </dev/stdin)
echo $mp3 > /tmp/quicklog
/opt/homebrew/bin/lame --preset extreme $mp3

(I have also tried using pbpaste and setting a named variable to the path instead of stdin, but still no success.)

I have added some steps to the KM script to see where it's failing, and get correct expected results at every stage, including tailing /tmp/quicklog (which shows the correct path).
If I run the last line above manually, replacing $mp3 the path copied from the line in the /tmp/quicklog file it succeeds without a problem.

I include the full path to Lame as you can see above, so I'm hoping it's not a path issue.

❯ which lame

Can someone please help me figure out where I'm going wrong? I thought that by using full paths I would avoid env issues.

Hello, welcome to the forum.

I could be wide of the mark here but doesn't $mp3 lack the "/tmp/quicklog/" part of the path before the filename?

Thanks for your reply Kevin.
That quicklog file is just a troubleshooting measure to try figure out why it's not working. It prints the contents of the clipboard, which is the
I did the following instead:

echo /opt/homebrew/bin/lame --preset extreme "$mp3" >> /tmp/quicklog

which simply writes out the whole command into that temporary log file. If I copy and paste the contents of that line into a shell it works perfectly, which is what had me stumped.

I ended up writing a wee python script to do the actual encoding, then kicked that off with KM, sending the path to it.

1 Like

Possibly -- but is it correctly passed to lame?

Difficult to tell without knowing what you are passing in from stdin, but I suspect that quoting your variable:

/opt/homebrew/bin/lame --preset extreme "$mp3"

...will solve the problem. You'll also have to use a full path, i.e. no ~ expansion.

One debugging technique is to put
set -xv
at the top of your script and display all the output of your script

Ah! That’ll be useful in the future.

Many thanks.