`I have a script where I am attempting to read from a manifest file, translate DOS paths in that manifest to UNIX paths, and then operate on those files. Here is a snippet of code that I am trying to debug:
while read line
do
srcdir=$(printf '%s' "$line" | awk -F \\ -v OFS=/ '{ gsub(/\r|^[ \t]+|[ \t]+$/, "") } !NF { next } /^\\\\/ { sub(/^.*\\prj\\/, "\\prj\\") } { $1 = $1 } 1')
done < manifest.txt
My input file looks like this:
$ cat manifest.txt
\\server\mount\directory
When I debug my little shell snippet, I get the following:
+ read line
++ printf %s '\servermountdirectory
'
++ awk -F '\' -v OFS=/ '{ gsub(/\r|^[ \t]+|[ \t]+$/, "") } !NF { next } /^\\\\/ { sub(/^.*\\prj\\/, "\\prj\\") } { $1 = $1 } 1'
+ srcdir=\servermountdirectory
So... Either at read or at printf, the \
characters are being interpreted as escape characters -- how do I work around that?
Note... I know I could just run the while
loop in awk... the thing is that in my real program, I have other things inside that while
loop that need to be done with "$srcdir"
-- and for this, sh is the right tool... So I really need a solution in sh.