I know that to deal with spaces in file names you should wrap the entire file name between quotes but this is not working for this script, indeed what is happening is the exact opposite, it only works without using quotes and I don't understand why. Tested with gnome-terminal
.
echo "Drag and drop some file"
read FILE
NAME=$(basename "$FILE")
cp "$FILE" ~/foo/bar/"$NAME" && echo "Success!"
read -r FILE
– glenn jackman Sep 13 '22 at 01:14FILE
variable). Were you trying to put quotes around the FILE variable name in theread FILE
line or the NAME variable name inNAME=$(basename ...)
? – Sotto Voce Sep 13 '22 at 01:33my file.txt
it works but"my file.txt"
or'my file.txt'
doesn't – Sep 13 '22 at 01:45/home/foo/abc 123.txt
is not supposed to work (because of the space between "abc" and "123"), but works, while typing"/home/foo/abc 123.txt"
which is supposed to work, doesn't. Dragging and dropping the file into the terminal window instead of typing (as suggested by the script) doesn't work either (because gnome-terminal automatically wraps the path within single-quotes, as stated in the following answer: https://stackoverflow.com/a/32060406 ). – Sep 13 '22 at 03:15read
you used. The factgnome-terminal
adds quotes does not mean all tools expect this. The answer you linked to uses some code to parse data coming fromgnome-terminal
; your snippet does not. Your belief about what is or is not supposed to work does not match what actually works. "How is it possible that this doesn't work?" – "Protocol" mismatch. – Kamil Maciorowski Sep 13 '22 at 06:42read
? So that the name of a file calledmy file
is entered as'my file'
or"my file"
? – Kusalananda Sep 13 '22 at 09:05