我寫了一個腳本運行時,它可以作爲一個簡單的腳本中隱藏用戶輸入的腳本,但我想融入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