Sed and awk backslash characters

Hi,

I have a variable read from user input:
PROFILESROOTDIR="\\194.185.82.188\CMSRepository\EncodingProfiles"

awk -F"=" -v gr=$PROFILESROOTDIR '/ProfilesRootDirectoryFromXOEMachine/{$2=gr;}1' OFS="=" $CFGFILE > "${CFGFILE}_new"

For this awk to work properly I need to replace in the variable each \ character with \\\ using sed but I just can't manage to do that.

Thanks,
Bianca

echo '\\194.185.82.188\CMSRepository\EncodingProfiles' | sed 's%\\%\\\\\\%g'

If I use this in the script
PROFILESROOTDIR1=`echo $PROFILESROOTDIR |sed 's%\\%\\\\\\%g'`

I get
sed: -e expression #1, char 9: unterminated `s' command

Bianca

I think it should be / instead of % in the code..

Try this:

PROFILESROOTDIR=$(echo $PROFILESROOTDIR | sed 's%\\%\\\\\\%g')

There is a problem with function used to read user's input
readDefault()
{
ARGS=""
N=1
LOCALBUF=""
until [ $N -eq $# ]
do
eval ARG=\${$N}
ARGS=" $ARGS $ARG"
N=`expr $N + 1`
done
read $ARGS LOCALBUF
if [ -n "$LOCALBUF" ]
then
VARNAME=${!#}
export $VARNAME=$LOCALBUF
else
echo "Using current value."
fi
}

echo "Please type directory where the profiles are placed: \(current value: $PROFILESROOTDIR\)"

readDefault -e PROFILESROOTDIR

In this function the \ character is ignored from variable given by user and removed from it.

DO you have any ideea how to ignore the \ characters in this function?

Thanks,
Bianca

The read command parses backslashes. If you have a reasonably modern shell, it might have read -r for "raw" input without any special treatment of backslashes.

I use the customized function so that if the user just press ENTER the variable's value is kept as the default one. If I use read -r PROFILESROOTDIR if the user just hits ENTER the variable will be set to empty.

I will user read -r inside the customized function.

Thanks,
Bianca