I need to prompt the user for a folder-path to SCP that folder from a server to my computer.
Since I know that there's a space in the folder-name (which cannot be omitted, unfortunately) I try to make that work, but I cant.
Currently I have
#copy.sh
read -r -p "Plot date: " plot_date
scp -r user@server:/home/user/Documents/projects/pages/$plot_date Plots/
where I know that plot_date
is on the form yyyy-mm-dd hh.mm
e.g 2021-09-06 10.51
, but that does not work e.g:
./copy.sh
Plot date: 2021-09-06 10.51
user@server's password: *******
scp: /home/user/Documents/projects/pages/2021-09-06: No such file or directory
cp: cannot stat '17.10': No such file or directory
which seems like, it splits up the date and the hour.
I have tried include some double-quotes based on this SO answer i.e
#copy.sh
read -r -p "Plot date: " plot_date
scp -r user@server:/home/user/Documents/projects/pages/"$plot_date" Plots/
which throws almost the same error
scp: /home/user/Documents/projects/pages/2021-09-06: No such file or directory
scp: 17.10: No such file or directory
I have tried save the input into another variable and use that (to ommit the string in the path)
read -r -p "Plot date: " plot_date
p_date="$plot_date"
scp -r user@server:/home/user/Documents/projects/pages/$p_date Plots/
which throws the same error as just above.
Atlast I have tried putting the entire path in a string i.e
read -r -p "Plot date: " plot_date
p_date="$plot_date"
scp -r "user@server:/home/user/Documents/projects/pages/$plot_date" Plots/
which throws the same error as the bottom 2 errors.
Now I'm really out of things to try
EDIT:
The answer here is regarding the user input, which forces the user to input as 2021-09-09\ 17\.51
. I want to do the handling in the script i.e making the user able to just write 2021-09-06 17.51
as input