Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么mkdir的行为在不同的Linux发行版上有所不同? 我试图用下面的C++程序创建名为1 2到3的文件夹。我可以在RHEL中成功地实现这一点。 然而,它在ubuntu 13.10中创建了一个名为{1..4}的文件夹_C++_System - Fatal编程技术网

为什么mkdir的行为在不同的Linux发行版上有所不同? 我试图用下面的C++程序创建名为1 2到3的文件夹。我可以在RHEL中成功地实现这一点。 然而,它在ubuntu 13.10中创建了一个名为{1..4}的文件夹

为什么mkdir的行为在不同的Linux发行版上有所不同? 我试图用下面的C++程序创建名为1 2到3的文件夹。我可以在RHEL中成功地实现这一点。 然而,它在ubuntu 13.10中创建了一个名为{1..4}的文件夹,c++,system,C++,System,为什么会发生这种情况?谢谢你帮助我 #include <cstdlib> int main() { std::system("mkdir {1..4}"); } 似乎系统默认使用sh…谢谢您的回答 一点术语:Linux中有文件夹,而不是“文件夹”(文件夹可能会直观地显示在桌面上,但这是一个桌面细节) 您不需要使用(正在运行sh而不是bash!)。 POSIXsh不知道{1..4}符号,因此{1..4}字符串被逐字传递给/bin/mk

为什么会发生这种情况?谢谢你帮助我

    #include <cstdlib>

    int main()
    {
        std::system("mkdir {1..4}");
    }

似乎系统默认使用sh…谢谢您的回答

一点术语:Linux中有文件夹,而不是“文件夹”(文件夹可能会直观地显示在桌面上,但这是一个桌面细节)

您不需要使用(正在运行
sh
而不是
bash
!)。 POSIX
sh
不知道
{1..4}
符号,因此
{1..4}
字符串被逐字传递给
/bin/mkdir
命令(请参阅…)

要测试
sh
是否不理解
{1..4}
符号

(因此,这是旧RHEL中的一个bug,其中可能
/bin/sh
是指向
/bin/bash
的符号链接,而在Debian和Ubuntu上,它是指向更符合Posix且更快的
/bin/dash
的符号链接)

只需使用系统调用和代码

#include <cstdlib>
#include <cstdio>
#include <sys/stat.h>
#include <sys/types.h>

int main() {
   for (int i=1; i<=4; i++) {
      char buf[8];
      snprintf(buf, sizeof(buf), "%d", i);
      if (mkdir(buf, 0755))
        { perror("mkdir"); exit(EXIT_FAILURE); };
   }
}
#包括
#包括
#包括
#包括
int main(){

对于(inti=1;i一点术语:Linux在其内部有,而不是“文件夹”(文件夹可能会直观地显示在桌面上,但这是一个桌面细节)

您不需要使用(正在运行
sh
而不是
bash
!)。 POSIX
sh
不知道
{1..4}
符号,因此
{1..4}
字符串被逐字传递给
/bin/mkdir
命令(请参阅…)

要测试
sh
是否不理解
{1..4}
符号

(因此,这是旧RHEL中的一个bug,其中可能
/bin/sh
是指向
/bin/bash
的符号链接,而在Debian和Ubuntu上,它是指向更符合Posix且更快的
/bin/dash
的符号链接)

只需使用系统调用和代码

#include <cstdlib>
#include <cstdio>
#include <sys/stat.h>
#include <sys/types.h>

int main() {
   for (int i=1; i<=4; i++) {
      char buf[8];
      snprintf(buf, sizeof(buf), "%d", i);
      if (mkdir(buf, 0755))
        { perror("mkdir"); exit(EXIT_FAILURE); };
   }
}
#包括
#包括
#包括
#包括
int main(){

对于(int i=1;i最有可能的是
mkdir
的行为在两个系统之间是不同的。您检查了手册页吗?另外,您是否运行相同的shell?最有可能的是
mkdir
的行为在两个系统之间是不同的。您检查了手册页吗?另外,您是否运行相同的shell?
sh-c'echo{1..4}“
和对std::system的C调用在Ubuntu 12.04上为我创建了4个文件夹。尽管使用/bin/dash的行为与您所描述的一样。您是否了解这是否是Ubuntu 12.04和13.10之间发生了变化?或者Vincent是如何进入这个位置的?@Enfulfourtowl:我目前没有Ubuntu(只有Mint和Debian),但我可能猜,
dash
已经改进了…
sh-c'echo{1..4}“
和对std::system的C调用在Ubuntu 12.04上为我创建了4个文件夹。尽管使用/bin/dash的行为与您所描述的一样。您是否了解这是否是Ubuntu 12.04和13.10之间发生了变化?或者Vincent是如何进入这个位置的?@Enfulfourtowl:我目前没有Ubuntu(只有Mint和Debian),但我可能猜,
dash
已经改进了。。。
#include <cstdlib>
#include <cstdio>
#include <sys/stat.h>
#include <sys/types.h>

int main() {
   for (int i=1; i<=4; i++) {
      char buf[8];
      snprintf(buf, sizeof(buf), "%d", i);
      if (mkdir(buf, 0755))
        { perror("mkdir"); exit(EXIT_FAILURE); };
   }
}