kwasserman
Technical User
I'm trying to use the following awk script to output a Windows batch file that will create home directories for new users on a Windows box. The script reads from a newuser.txt setup file and pulls the username from the second field. Since Windows uses backslashes for directory paths, I need to escape the backslash. The Windows path needs to be read from the WINDIR variable, since we have several different home directory paths for different user groups.
WINDIR="E:\\home\\directory\\"
awk -F: -v windir=$WINDIR '{print "mkdir "windir""$2""}' newuser.txt > makewindir.tmp
cat makewindir.tmp >> makehome.bat
When I run this script, all backslashes are removed, and the output looks like this:
mkdir E:homedirectoryuser1
mkdir E:homedirectoryuser2
mkdir E:homedirectoryuser3
I've tried every escape and quoting sequence that I can think of to make this work.
WINDIR="E:\\home\\directory\\"
awk -F: -v windir=$WINDIR '{print "mkdir "windir""$2""}' newuser.txt > makewindir.tmp
cat makewindir.tmp >> makehome.bat
When I run this script, all backslashes are removed, and the output looks like this:
mkdir E:homedirectoryuser1
mkdir E:homedirectoryuser2
mkdir E:homedirectoryuser3
I've tried every escape and quoting sequence that I can think of to make this work.