I have this bash script:
#!/bin/bash OriginFilePath="/home/lv2eof/.config/google-chrome/Profile 1/" OriginFileName="Bookmarks" OriginFilePathAndName="$OriginFilePath""$OriginFileName" DestinationFilePath="/home/Config/Browser/Bookmarks/ScriptSaved/Chrome/Profile 1/" DestinationFileName=$(date +%Y%m%d-%H%M%S-Bookmarks) DestinationFilePathAndName="$DestinationFilePath""$DestinationFileName" echo cp \"$OriginFilePathAndName\" \"$DestinationFilePathAndName\" cp \"$OriginFilePathAndName\" \"$DestinationFilePathAndName\"
When I execute it from the command line I get this output:
[~/] lv2eof@PERU $$$ csbp1 cp "/home/lv2eof/.config/google-chrome/Profile 1/Bookmarks" "/home/Config/Browser/Bookmarks/ScriptSaved/Chrome/Profile 1/20211207-001444-Bookmarks" cp: target '1/20211207-001444-Bookmarks"' is not a directory [~/] lv2eof@PERU $$$
So I get an error and the file isn't copied. Nevertheless if I issue in the command line the command:
[~/] lv2eof@PERU $$$ cp "/home/lv2eof/.config/google-chrome/Profile 1/Bookmarks" "/home/Config/Browser/Bookmarks/ScriptSaved/Chrome/Profile 1/20211207-001444-Bookmarks" [~/] lv2eof@PERU $$$
As you can see everything works fine and the file is copied. Shouldn't the commands work the same inside and outside bash scripts? What am I doing wrong?
echo
instead of-x
.cp \"/home/lv2eof/.config/google-chrome/Profile 1/Bookmarks\" \"/home/Config/Browser/Bookmarks/ScriptSaved/Chrome/Profile 1/20211207-001444-Bookmarks\"
in the terminal and you'll get the same error.