I have a script for converting Handbrake videos, but I want to make presets. I am having trouble with the script, in the end it outputs something like

    HandBrakeCLI -i file.avi -o file.mp4 flags

But I can't get the flags part to work, so to troubleshoot I want to see what the command line is receiving as a translation of my script.

Here is the link to my working script

How to Install Handbrake and Convert recursive file tree's

Here is what I would like it to look like

Only the changes are shown

    FLAGS="-E ac3 -6 5point1 -R 48 -B 448 --audio-fallback ac3"
    if [ -z "$1" ] ; then
        find "$TRANSCODEDIR"/* -type f -exec bash -c 'HandBrakeCLI -i "$1" -o "${1%\.*}".mp4 "$FLAGS"' __ {} \;

Basically the $Flags option isnt working, and as I mess around it either doesn't find the file, or does and doesn't see the flags, help with the script is fine, but for future debugging of other scripts i wouldnt mind knowing how to just output the commands it "would" have sent to the shell instead just to the screen or a text file probably is better.


  • 1
    You probably need to export PRESET, or FLAGS. Otherwise it won't affect child processes like the new bash commands run by find. – muru Jul 16 '15 at 2:27
  • I tried export Flags to no avail, could you give me the line to export flags to the child process? – FreeSoftwareServers Jul 16 '15 at 3:19
  • Where did you put export FLAGS? I'd just change line 1 to export FLAGS="-E .... – muru Jul 16 '15 at 3:24
  • So I did this.. export FLAGS="-E ac3" exec "$@" and when I exit out back to shell and tpye FLAGS it says -E is not a known command, does that mean its not getting past -E or that is all the is getting exported – FreeSoftwareServers Jul 16 '15 at 3:25
  • O.o I don't understand what you did. DId you try to run FLAGS? WHere did exec "$@" come from? – muru Jul 16 '15 at 3:26

You can add set -x to the top of your bash script or (equivalently) run it using

 bash -x yourscript

See help set or the SHELL BUILTIN COMMANDS section of man bash:

  -x  Print commands and their arguments as they are executed.

There is more discussion at How to debug a bash script? on SE Unix & Linux

What you will probably see in this case is that $FLAGS variable is empty: it is enclosed in single quotes so gets passed literally to the bash -c subshell, where $FLAGS is undefined.

  • I already tried bash -x it gives me kinda the same verbose info handbrake would, im basically looking for a translation of my variables, because I suspect as you do, that its not being exported – FreeSoftwareServers Jul 16 '15 at 3:19
export FLAGS="-f mp4 -O --decomb=bob --loose-anamorphic --modulus 2 -e x264 -q 20 --vfr -E ac3 -6 5point1 -R 48 -B 448 --audio-fallback ac3 --encoder-preset=veryfast  --verbose=1"

Worked for me, thanks for the help guys, see the script in action at How to Install Handbrake and Convert recursive file tree's

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.