逃生"双引号"里面批的输入参数 [英] Escape "double quotes" inside batch's input parameters

查看:115
本文介绍了逃生"双引号"里面批的输入参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要运行批处理脚本它需要一个参数如下(路径)

I want to run the following in batch script where it takes an argument (a path)

runas /user:abc "icacls %1 /grant Everyone:(F) /T"

但参数%1 已经包含了一个(因为它是一个路径,通过对上下文菜单中的Send为了 - 我没有过这么多的控​​制)。
所以,当命令批处理脚本运行它运行如下:

but the argument %1 already contains a " (because it's a path, passed on by context menu's Send To - I don't have much control over this). So when the command runs in batch script it runs like this:

runas /user:abc "icacls "c:\folder" /grant Everyone:(F) /T"

所以,很显然,我需要在躲避 S按%1 创建。如何执行字符串操作%1 ,使得它逃过了引号?

So obviously I need to escape the "s created by %1. How do I perform string manipulation over %1 such that it escaped the quotes?

推荐答案

您应该能够使用 \\在这里是与您可能会发现有用一些其他的转义字符网站

You should be able to use \" Here is a site with a few other escape characters that you might find useful

要执行字符串替换:

set temp=%1
set temp=%temp:"=\"%
echo %temp%

这篇关于逃生"双引号"里面批的输入参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆