Question: Im creating an automator service that transcodes all the files within a folder to a compressor preset by running the following shell script:

```
VAR="/Applications/Compressor.app/Contents/MacOS/Compressor -batchname MyFirstBatch"
    for d in "$@"; do
        filename=$(basename "$d")
        fname="$(dirname "$d")"/"${filename%.*}"
        VAR+=" -jobpath "$d" -settingpath /Applications/Compressor.app/Contents/Resources/Settings/ProRes/proResHQName.setting -locationpath "$fname".mov"
    done
eval $VAR

```

The problem is that the resulting paths in the string have a **blank space** instead of **backslash and blankspace**, so I want to replace every **" "** in the **d** variable with a **"\ "**.

Also, is there any way to omit folders and only consider files?

Thank you.

Here's a screenshot of my workflow (Get specified Finder Items and Get folder Contents are just for testing purpose, I disable them when using it as a service):

[![Screenshot of Automator Service](https://i.stack.imgur.com/7x0pL.png)](https://i.stack.imgur.com/7x0pL.png)

Answer: 
I don't have Compressor.app to test with, but this should work:

```
fileargs=()
for d in "$@"
do
    [ -f "$d" ] || continue
    filename=$(basename "$d")
    fname="$(dirname "$d")"/"${filename%.*}"
    fileargs+=(-jobpath "$d" -settingpath /Applications/Compressor.app/Contents/Resources/Settings/ProRes/proResHQName.setting -locationpath "$fname".mov)
done

/Applications/Compressor.app/Contents/MacOS/Compressor -batchname MyFirstBatch "${fileargs[@]}"

```

EDIT: If you want to restrict it to just specific file extensions (.mov, .mp4, and .mxf), you can use this instead:

```
fileargs=()
for d in "$@"
do
    [[ "$d" =~ [.](mov|mp4|mxf)$ ]] || continue
    [ -f "$d" ] || continue
    fileargs+=(-jobpath "$d" -settingpath /Applications/Compressor.app/Contents/Resources/Settings/ProRes/proResHQName.setting -locationpath "${d%.*}".mov)
done

/Applications/Compressor.app/Contents/MacOS/Compressor -batchname MyFirstBatch "${fileargs[@]}"

```

Note that with this restriction, the filename is guaranteed to have an extension, so the `${d%.*}.mov` trick that @user3439894 suggested is safe to use. Also, is it ok to use the the same `-jobpath` and `-locationpath` names? (This'll happen when both the input and output files are .mov.)
> 
> take into account only .mov, .mp4 and .mxf files
> 
> 
> 

I modified the above script by Gordon Davisson. 
<https://apple.stackexchange.com/a/363864/44531>

This may need modification. I didn't understand the -locationpath option. I do not have compressor, so I merely **echo** the last line. Set debug to false when you get tired of the output. I no longer w-locationpathrite code without debug statements. 

```
#!/bin/bash
# question:
# https://apple.stackexchange.com/questions/363854/help-to-replace-a-blank-space-with-a-backslash-and-blankspace-in-a-variable-in-r
# compressor options:
# https://support.apple.com/kb/PH21248?viewlocale=en_KE&locale=en_KE

debug=true
fileargs=()
for d in "$@"
do
    [ debug ] && echo -e "\nProcessing file ${d}"

    filename=$(basename "$d")
    justname="${filename%.*}" 
    # Works for files with no extension
    fileext=""
    [[ "${filename}" == *"."* ]] &&  fileext="${filename##*.}" 

    #  Process these allowed extensions .mov, .mp4 and .mxf 
    [ "${fileext}" = "mov" -o "${fileext}" = "mp4" -o "${fileext}" = "mxf"  ] || continue

    [ debug ] && echo "filename is ${filename}   fileext is ${fileext}    justname is ${justname}"

    # make sure the file exists.
    [ -f "$d" ] || continue

    dirname=$(dirname "$d")
    [ debug ] && echo "dirname is ${dirname}"
    fname="${dirname}/${justname}"
    [ debug ] && echo "fname is ${fname}"

###
### I do not know what you want for locationpath 
###
 fileargs+=(-jobpath "$d" \
      -settingpath /Applications/Compressor.app/Contents/Resources/Settings/ProRes/proResHQName.setting \
      -locationpath "${fname}.${fileext}.mov")
done

echo /Applications/Compressor.app/Contents/MacOS/Compressor -batchname MyFirstBatch "${fileargs[@]}"

```