Hello, I am lost on a script I need to do
" have it query the user for the name of the file to be copied and the name to be given the copy"
I can only come up with
menu()
{
clear
echo -e '
1. Please enter a file name to be copied
2. Name the file
3. Exit
Enter your choice (1-3): \c'
read choice
}
menu
until [ $choice =3 ]
do echo
case "$choice"
in
1) echo -e "Enter a file to be copied: \c'"
read name
lu "$name"
echo
echo "press enter to continue"
...... etc etc
First of all - Is this homework? Read Rule #6. Because this smells like homework, I will not provide the solution but I will say that you are on the right track.
You dont really need the menu. But if you choose to use one, try the builtin select case command. It will create the menu for you. Also, the way that you have your choices doesnt really make sense. Think about the copy command (see man cp)and the arguments it takes. In its simplest form, it takes 2 file names. The first being the path and file to copy and the second being the path and new file name. Given that, your script could simply be:
Think about what your program flow will be. If you do, you will have a much easier time of programming it. (By the way, what class is this assignment for? )
Begin Script
-Prompt User to Enter A File Name To Copy
-Verify File Entered Exists
-----Prompt User to Re-enter if File does not exist
-Enter New Filename
-perform the copy
-End Script