Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

escape the backslash for Windows pathnames

Status
Not open for further replies.

kwasserman

Technical User
Oct 21, 2004
7
0
0
US
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.
 
Hi

Code:
WINDIR=[red]'[/red]E:\\home\\directory\\[red]'[/red]

[gray]# or[/gray]

WINDIR="E:[red]\[/red]\[red]\[/red]\home[red]\[/red]\[red]\[/red]\directory[red]\[/red]\[red]\[/red]\"

Feherke.
 
WINDIR="E:\\\\home\\\\directory\\\\"

This one worked. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top