Reputation: 107
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);
Upvotes: 1
Views: 64
Reputation: 107
As @Robin479 suggested in the comments, I was missing quotes for my file variable working code is as follow:
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}")"
Upvotes: 1