I'm trying to write a function for my Bash script to keep it DRY but for some reason the output of the code is not the same as when it's not inside a function.
What am I missing ?
Working:
#Get file name from file path
fileName="$(basename "$file")";
#Remove " ' and white space from name
fileName=${fileName//[\"\'\ ]/};
convert "$file" -resize $RESOLUTION\> "$OUTPUT_PATH"$fileName;
Not working:
function cleanUpName() {
#Get file name from file path
fileName="$(basename "$1")";
#Remove " ' and white space from name
echo ${fileName//[\"\'\ ]/};
}
convert "$file" -resize $RESOLUTION\> "$OUTPUT_PATH"$( cleanUpName $file);
$filereference. In fact, you are missing a lot of quotes, e.g. in the function's echo statement and around the$(…)subshell in the last line. This makes all these strings subject to multiple shell expansions.