我想使用shell脚本
更新backup.php文件,其中包含以下详细信息$source_server_ip = "";
$cpanel_account = "";
$cpanel_password = "";
有人可以指导我如何向用户询问以下问题并更新backup.php文件中的详细信息吗?
echo "Enter hostname: '$hostname'"
echo "Enter cPanel username: '$user'"
echo "Enter password: '$pass'"
我尝试了以下代码,但收到了错误
#!/bin/bash
echo "Your hostname: "
read hostname
echo "Your username:"
read user
echo "$source_server_ip = "$hostname;"" >> backup.php
echo "$cpanel_account = ""$user""; >> backup.php
由于
答案 0 :(得分:1)
通过这种方式,你可以尝试这个
#!/bin/bash
read -p "Enter hostname: " hostname
read -p "Enter cPanel username: " user
read -p "Enter password: " pass
if [ -f "backup.php" ]
then
rm backup.php
fi
echo "\$source_server_ip = \"$hostname\";" >> "backup.php"
echo "\$cpanel_account = \"$user\"; " >> "backup.php"
echo "\$cpanel_password = \"$pass\"; " >> "backup.php"
内置read
命令会停止脚本并等待用户从键盘输入内容。 -p
(提示)是一种速记功能,它结合了printf
和read
语句。 read在等待用户响应之前显示一条短消息。