0

I am trying to edit a script I found online. The script is supposed to convert all files in a directory and place them in another directory (Using handbrake) but it only passes the first word of the file and not the subsequent words or the file extension

#!/bin/bash
SRC="/var/www/mediacenter/convert"
DEST="/var/www/mediacenter/converted"
DEST_EXT=mp4
HANDBRAKE_CLI=HandBrakeCLI
#PRESET = " -e x264 -E av_aac -q 22"

for FILE in "$SRC"/*
do
filename=$(echo $FILE | cut -f 1 -d '.')
extension="${filename##*.}"
filename="${filename%.*}"
echo $filename.$DEST_EXT
$HANDBRAKE_CLI -i "$FILE" -o $FILE.$DEST_EXT  $PRESET
done

The echo works and I have tried quoting it but can't find the right combination.

Community
  • 1
  • 1
  • add `set -x` on line before `$HANDBRAKE_CLI` and `set +x` after it. You'll see lines with a leading `+` sign, and all strings will be "normalized" to use single-quotes. Then you'll see what command is being run, and understand better where to change/fix your quoting or variable assignments. Good luck. – shellter Jan 26 '16 at 03:39
  • 2
    In general, when asking a question, try to create a title that describes the problem, rather than your status. That way, other people can search for the problem and find your question, and people who know the answer will see it in a list and be able to find and answer it. Saying this is a "beginner bash script problem" helps know one. – dimo414 Jan 26 '16 at 03:45

1 Answers1

2

You need to add double quotes when a file name contains whitespace.

$HANDBRAKE_CLI -i "$FILE" -o "$FILE.$DEST_EXT" $PRESET
Liang Liu
  • 21
  • 5