Sed: removes \ from text which causes issues

Hi all,

Hoping someone hoping someone might be able to help. i've got the following sed command which i'm using in a bash script that i'm trying to use to insert a new line into an already existing file so i don't have to manually enter it when setting stuff up. the existing script test2/3 are just scripts to move files/ folders etc.

sed "113a\mv -v $DISK2/$SHOW\ folder2 $DISK/$SHOW/$FOLDER1" test3.sh > test2.sh

The problem i am having is that when the script resolves the first $SHOW it removes the "\" that is right after it which is used to show its a name with a space within the command line.

expected outcome:

mv -v /disk/disk2/Test\ folder2 /disk/disk1/Test/folder

actual outcome:

mv -v /disk/disk2/Test folder2 /disk/disk1/Test/folder

is there a way for sed to leave the "\" alone so it won't effect my script?

Also, if $SHOW has a space in the name is there a way to either put a "\" in so it will work or another way that it won't cause that mv command to fail.

$ echo xx | sed "1a\mv -v DISK2/SHOW\ folder2 DISK/SHOW/FOLDER1"
xx
mv -v DISK2/SHOW folder2 DISK/SHOW/FOLDER1
$ echo xx | sed "1a\mv -v DISK2/SHOW\\ folder2 DISK/SHOW/FOLDER1"
xx
mv -v DISK2/SHOW folder2 DISK/SHOW/FOLDER1
$ echo xx | sed "1a\mv -v DISK2/SHOW\\\ folder2 DISK/SHOW/FOLDER1"
xx
mv -v DISK2/SHOW\ folder2 DISK/SHOW/FOLDER1
$ echo xx | sed "1a\mv -v DISK2/SHOW\\\\ folder2 DISK/SHOW/FOLDER1"
xx
mv -v DISK2/SHOW\ folder2 DISK/SHOW/FOLDER1

Thanks,

I put a tripple \ in the command and it worked.

any idea if its possible as well with the 2nd part of the question? if $SHOW contains a space in the name if its possible to put the space in it?

I would try the following, putting escaped "double quotes" around the SHOW variable. I cannot guarantee it will work, as the testing is a bit awkward, but I think a good chance it will work:

sed "113a\mv -v $DISK2/\"$SHOW\"\\\ folder2 $DISK/\"$SHOW\"/$FOLDER1" test3.sh > test2.sh

If possible to remove those blanks from files names, I would encourage that. Those blanks in file names cause so many irritations. :eek: