0

I am a complete beginner in this topic and I usually search for a solution rather than just asking a question because I am sure that somebody had a similar problem. But this time I couldn't find a way to solve my problem.
So I wrote a little shell script that uses rclone to copy files from a variable folder into my Google Drive.
My problem is that I can't enter the folder name if it contains more than one word. I already tried using read -r folder but it returns

Command copy needs 2 arguments maximum: you provided 3 non flag arguments: ["One" "Folder/" "Drive:SomeFolder/File"]

and if I use \ it returns

Command copy needs 2 arguments maximum: you provided 3 non flag arguments: ["One\\" "Folder/" "Drive:SomeFolder/File"]

I want the final command to look like this

rclone copy One\Folder/ Drive:SomeFolder/File
#!bin/sh
#upload

echo "Folder Name:"
read -r folder
echo "File Name:"
read -r name
rclone copy ${folder}/ Drive:SomeFolder/${name} 
Toto
  • 89,455
  • 62
  • 89
  • 125
JohnTM
  • 1
  • 1
  • `help read` (in newer `bash`es), will show you `-r` for `raw` ; "do not allow backslashes to escape any characters". I'm not certain that's what you're looking for, so check out the other options listed. Good luck. – shellter Aug 16 '21 at 01:49
  • The problem is the way you invoke `rclone`, not the way you read the variables. You need to quote variable expansions. [ShellCheck](https://www.shellcheck.net) automatically detects this and other common problems. – that other guy Aug 16 '21 at 01:53
  • @thatotherguy Thank you so much! I will print this website on a piece of paper and put it on my wall. – JohnTM Aug 16 '21 at 02:00
  • Btw how do I set this question as answered? – JohnTM Aug 16 '21 at 02:00
  • Most editors also have plugins for this tool so that you can get the same suggestions while you write the script. – that other guy Aug 16 '21 at 04:18

1 Answers1

0

The problem is the way you invoke rclone, not the way you read the variables. You need to quote variable expansions. ShellCheck automatically detects this and other common problems. – that other guy

JohnTM
  • 1
  • 1