Reputation: 29
im writing a script that allows the user to create a backup of a file they choose by allowing them to input the file name. the file will then have backup followed by being date stamped at the end of it's name and saved on the home drive. but whenever i try to run it i get an error: cp: missing destination file operand after '_backup_2017_12_16'
here's my code:
title="my script 3"
prompt="Enter:"
options=("create a backup of a file")
echo "$title"
PS3="$prompt "
select opt in "${options[@]}" "Quit"; do
case "$REPLY" in
esac
cp "$filename""${file}_backup_$(date +%Y_%m_%d)"
done
Upvotes: 0
Views: 84
Reputation: 7509
case
statement is currently empty. You need it to handle your chosen optioncp source dest
Quit
in thereread
command is used to get user inputPutting it all together, your script could look like this:
#!/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
Upvotes: 2