shell中单引号怎么转义

图片描述

const exec = require('child_process').exec;
          exec('cat /dev/urandom |od -x|tr -d ' '|head -n 1', (error, stdout, stderr) => {
            if (error) {
              console.error(`exec error: ${error}`);
              return;
            }
            console.log(`stdout: ${stdout}`);
            console.log(`stderr: ${stderr}`);
          });

上面的shell命令中单引号怎么转义?加反斜杠不行

阅读 4.3k
2 个回答

换双引号?
exec("cat /dev/urandom |od -x|tr -d ' '|head -n 1", (error, stdout, stderr) => {

const exec = require('child_process').exec;

      exec('cat /dev/urandom |od -x|tr -d “ ”|head -n 1', (error, stdout, stderr) => {
        if (error) {
          console.error(`exec error: ${error}`);
          return;
        }
        console.log(`stdout: ${stdout}`);
        console.log(`stderr: ${stderr}`);
      });
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进