Reputation: 723
I'm writing a bash script that needs to take in a file name, and it may be something like:
"filename - Copy.txt"
When I try to get the file name of this file, basename seems to pick up the dash as an operand and fails.
basename: extra operand "Copy"
I have some like this:
echo $(basename -- $eachFile)
Upvotes: 5
Views: 5122
Reputation: 40789
Use echo $(basename "$eachFile")
to avoid the bash interpreter from seeing the spaces in the file name as spaces between arguments to basename
Upvotes: 5