我正在编写一个脚本,允许用户通过允许他们输入文件名来创建他们选择的文件的备份。然后,该文件将进行备份,然后在其末尾标记日期并保存在主驱动器上。但每当我尝试运行它时,我都会收到一个错误:cp:在' _backup_2017_12_16'
之后缺少目标文件操作数这是我的代码:
function sendMediaGroup($files)
{
$url = "https://api.telegram.org/bot" . $this->token . "/" . __FUNCTION__;
$media = [];
$ch = curl_init();
$type = "photo";
$caption = "";
foreach ($files as $file)
{
$media[] = [
'type' => $type,
'media' => $file['tmp_name'],
'caption' => $caption
];
}
$disable_notification = false;
$reply_to_message_id = null;
$parameters = [
'chat_id' => $this->chat_id,
'media' => json_encode($media),
'disable_notification' => $disable_notification,
'reply_to_message_id' => $reply_to_message_id,
];
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:multipart/form-data"));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
return $output = curl_exec($ch);
}
答案 0 :(得分:2)
case
声明目前为空。您需要它来处理您选择的选项cp source dest
Quit
放在那里read
命令用于获取用户输入总而言之,您的脚本可能如下所示:
#!/usr/bin/env bash
options=("Backup" "Quit")
prompt="Enter: "
title="My script 3"
echo "$title"
PS3=$prompt
select opt in "${options[@]}"; do
case $opt in
"Backup")
IFS= read -r -p "Enter filename: " filename
cp -- "$filename" "${filename}_backup_$(date +%Y_%m_%d)" && echo "Backup created..."
;;
"Quit") break ;;
*) echo "Wrong option..." ;;
esac
done