使用-c标志交互式地执行bash代码

我正在尝试运行与bash解释器的shell片段。 使用-c标志允许我直接将命令提供到命令行而不写入文件。 这是我的使用所必需的。

工作示例:

 $ bash -c 'free -m' 

问题是我想运行的实际shell片段中有单引号。

 find / -type f -size +50M -exec ls -lh {} \; | awk '{ print $9 ": " $5 }' 

我想只是逃避报价将工作:

 $ bash -c 'find / -type f -size +50M -exec ls -lh {} \; | awk \'{ print $9 ": " $5 }\'' 

但是这不起作用。 它不执行命令。

另外,同样的问题,我需要能够从命令行执行Node.js而不写入文件。

 $ node -e 'console.log("hello");' 

以上的作品,但是:

 $ node -e 'console.log('hello');' and $ node -e 'console.log(\'hello\');' 

两者都打破。

想法? 谢谢。

尝试这个:

$ bash -c $'find / -type f -size +50M -exec ls -lh {} \; | awk \'{ print $9 ": " $5 }\''

man bash

  Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash escape sequences, if present, are decoded as follows: \a alert (bell) \b backspace \e an escape character \f form feed \n new line \r carriage return \t horizontal tab \v vertical tab \\ backslash \' single quote \nnn the eight-bit character whose value is the octal value nnn (one to three digits) \xHH the eight-bit character whose value is the hexadecimal value HH (one or two hex digits) \cx a control-x character