我写了一个脚本运行时,它可以作为一个简单的脚本中隐藏用户输入的脚本,但我想融入C程序,但它提供了以下错误:运行在C程序
warning: missing whitespace after macro name
error: expected ')' before '$pass'
这里的程序:
#include"header.h"
#define SHELLSCRIPT"\
#bin/bash\n\
echo 'Password Please:'\n\
stty -echo\n\
read pass\n\
stty echo\n\
printf'\n'\n\
sleep'2'\n\
echo "$pass"\n\
"
int main()
{
puts("Will execute sh with following script:");
puts("SHELLSCRIPT");
puts("Starting now");
system(SHELLSCRIPT);
return 0;
}
如果我更换
echo "$pass" with echo '$pass'
,它运行,但打印:
Will execute sh with following script
SHELLSCRIPT
Starting now
Password Please:
$pass
,而不是通过$在最后的时候在密码提示请它应该打印用户输入的数据:
我到底做错了什么?
1)不要添加不相关的标签,也不要添加不相关的信息。这里没有涉及C代码。 2)这在安全性方面看起来非常糟糕。使用PAM进行用户验证! – Olaf
是谷歌还是维基百科失望? https://en.wikipedia.org/wiki/Pluggable_authentication_module – Olaf