Ask Your Question

Reference var in command

asked 2018-09-07 15:59:20 -0600

cmchoi gravatar image

updated 2018-09-10 08:56:40 -0600

DarylW gravatar image

My code:

    $userpwd = lookup('sfsadmpwd')

  exec { 'Connect UNC DX11':
    command => "C:\Windows\System32\cmd.exe /c "net use \\\\server\\sw-puppet /user:windemo\test1 ${userpwd}"",

I get:

Warning: Unrecognized escape sequence '\c' 
Error: Could not parse for environment production: Syntax error at 'net'

What is proper syntax to use var reference?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-09-10 09:39:13 -0600

HBlock gravatar image

If I read this correctly, you need to quote the inner double quotes, so it should be:

command => "C:\Windows\System32\cmd.exe /c \"net use \\\\server\\sw-puppet /user:windemo\test1 ${userpwd}\"",
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2018-09-07 15:59:20 -0600

Seen: 31 times

Last updated: Sep 10