在shell命令中转义文件名

时间:2019-11-18 14:57:07

标签: c++ linux shell

我正在编写C ++代码,该代码生成一个Shell脚本,该脚本创建目录并将文件复制到其中。文件/目录名称可以由任何可能的允许字符组成。我需要转义那些文件/目录名称。我需要脚本可以被人类阅读,因此我想使用尽可能少的转义符甚至引号。例如:

mkdir \a\b\c

mkdir 'abc'

mkdir abc

目录/文件名甚至可以包含\ n,\ r和\ t字符。我还没有想出如何从命令行创建具有这种名称的文件。

您能帮我使用“ mkdir_command”功能吗?

std::string mkdir_command(const char * buf, size_t size) {
    // Buf can contain anything! 
    // It generates "mkdir ..." command which can be used in a shell script.
    // The function throws only in case there is a character ...
    // ... which is not allowed in the directory name, like '/' or 0.
}

0 个答案:

没有答案
相关问题