我正在嘗試爲Linux系統用戶更改密碼編寫應用程序。
下面是該代碼:
shell_exec("/usr/bin/passwd ".$user." <<EOF\n".$password."\n".$password."\nEOF");
它把所有的空間接受字符 「$」
如何通過 「$」 在了shell_exec?
在此先感謝。
我正在嘗試爲Linux系統用戶更改密碼編寫應用程序。
下面是該代碼:
shell_exec("/usr/bin/passwd ".$user." <<EOF\n".$password."\n".$password."\nEOF");
它把所有的空間接受字符 「$」
如何通過 「$」 在了shell_exec?
在此先感謝。
你可以使用\$
來逃避它,或在單引號內包含你的字符串內容。因爲單引號不展開變量
shell_exec('/usr/bin/passwd $'.$user." <<EOF\n".$password."\n".$password."\nEOF");
或者你也可以在命令字符串傳遞給shellescapearg
如下
$arg = $user." <<EOF\n".$password."\n".$password."\nEOF";
shell_exec('usr/bin/passwd ' . $arg);
我不認爲錯誤是關係到$
符號。一個類似於你的代碼對我來說工作得很好。
我用下面的測試:。。。。
$msg = "Hello world"; shell_exec("notify-send ".$msg);
嘗試使用$ password =「test $ 123」更改Linux用戶密碼,然後檢查 –
不確定我是否理解您所說的內容,但是這是:'$ msg =「Hello $ world」; shell_exec(「notify-send」。$ msg);'工作。 – xou816
我試過以下腳本:'$ user ='test'; $ pass ='test $ a'; echo $ pass; $ arg = $ user。「<< EOF \ n」。$ pass。「\ n」。$ pass。「\ nEOF」; \t \t \t shell_exec('/ usr/bin/passwd'。$ arg);'但是不行。 –
'了shell_exec( '的/ usr/bin中/ passwd文件$' $用戶 「<< EOF \ n」 $密碼 「\ n」 $密碼。「\ nEOF」);'不起作用。 –
什麼不行?你試圖更改用戶的密碼,然後丟失當前的密碼, – DevZer0
嘗試用$ password =「test $ 123」更改Linux用戶密碼,然後檢查 –