'File path that modified by concatenating variables not working

I'm trying to make this work. Please help.

folder="Test\ Folder"
path="/Volumes/Macintosh\ HD/Users/Shared/${folder}"
echo "$path"
if [ -d "$path" ]; then
echo "Yes"; else echo "No"
fi

This is the original script I'm working on.

echo in point
read inp
echo out point
read op
echo path
read ffolder

fName=`echo "$ffolder" | cut -d'/' -f1`

makejpgs () {
        ffmpeg -y -i "${3}" -ss $1 -to $2 -vf fps=12 "$fName_%d.jpg"
}

path="/Volumes/PROJECTS/Main/${fName}"
files=$(find "$path" -type f -name "*story*")
echo "$files"

for i in $files; do

    echo "$i"
    makejpgs "$inp" "$op" "$i"

done

ffmpeg giving error when not using \ .



Solution 1:[1]

If you have a value "between quotes", then you do not need to escape\ spaces. So, change each \ into just .

Solution 2:[2]

You can escape special characters in your input.

echo path
read ffolder
ffolder=$(echo $ffolder | sed 's/[`~!@#$%^&*() -_=+{}\|;:",<.>/?'"'"']/\\&/g')

On input of my desktop it will return my\ desktop and similarly for [my folder] it will return \[my\ folder\].

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marlon Richert
Solution 2 sauraj