A Perl system call must send exactly both characters single & double quote ' \"

左心房为你撑大大i 提交于 2019-12-08 05:10:29

If you want to execute a system command and don't have to use any shell syntax like redirects, it's usually better and safer to use the list form of system:

system(
    'cleartool',  'mkattr', '-replace', 'ATTRIBUTE',
    qq{"$attribute"}, qq{lbtype:$label}
);
# or, if you really want to pass both types of quotes:
system(
    'cleartool',  'mkattr', '-replace', 'ATTRIBUTE',
    qq{'"$attribute"'}, qq{lbtype:$label}
);

See perldoc -f system

It's not clear from your question if you want to pass '"XYZ"' or "XYZ".

See "Quote and Quote like Operators" and use qq{...}:

system(qq{cleartool mkattr -replace ATTRIBUTE '"$attribute"' lbtype:$label});

qq{...} is exactly like "..." except you can then use double quotes " in your string without escaping them.

You can use any character directly after the qq and must then use the same character to denote the end-of-string, i.e. qqX...X would work the same way. You would run into problems if your string contains Xes, so don't do that.

You can also use paired characters as delimiter ({}, (), <>) which is what you usually will see.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!