Here it is. The only thing I changed from the original code was what he suggested.
This error is a common in linux. For example, if I wanted to move a folder called
"Edited Files" from /shared to /ftp, I'd have to enter this command into terminal:
sudo mv -f /shared/Edited\ Files /ftp/.
If I have just this:
sudo mv -f /shared/Edited Files /ftp/.
(with no backslash before the space), linux would treat is as 2 separate folders.
My problem getting my bash script to insert a backslash before any special character
(spaces, parenthesis, etc.).
Here is my current code:
Code:
#!/bin/bash
echo List files in storage folder [y/n]?
read ONE
if [ $ONE = "y" ]; then
sudo ls ../shared
fi
echo List files in FTP folder [y/n]?
read TWO
if [ $TWO = "y" ]; then
sudo ls ../ftp
fi
echo Copy or move [m/c]:
read THREE
if [ $THREE = "m" ]; then
THREE="sudo mv -f"
else
THREE="sudo cp -R"
fi
echo Name of folder:
read FOUR
echo "(Storage to FTP) or (FTP -> Storage) [a/b]: "
read FIVE
if [ $FIVE = "a" ]; then
$THREE ../shared/${FOUR} ../ftp/.
else
$THREE ../ftp/${FOUR} ../shared/.
fi
<edited by jbsnake>
if you notice above you don't have ${FOUR} quoted... which is what crouse was saying to do
that is why you are getting the broken arguments...
if you change the above from reading ${FOUR} to "${FOUR}" it will be fixed without the need of adding any \ anywhere.
</edit>
Thanks.