Interactive script for copying files from one location to another
Hi,
I am writing an interactive script for tar-ing a folder and copying it to another location for backup (/opt/backup) and the elif loop used is not ending after executing the contents once, it becomes an infinite loop. What could the error be? please suggest.. Code:
The script - |
Whenever you post a script, command output, or similar text, it's useful to readers to place that text between code tags. For instance, if you were to type in your post/response/message:
[code]This is standard width text. It's easier to read code/output with[/code] You would get a box like below: Code:
This is standard width text. To your question... Your loop is started with: Code:
while [ "$guess" = "$name" ]; do EDIT: As a side note, the structure of your script does not match what you're (probably) aiming for. My guess is your intent is to loop around the menu-input sequence until the user selects a valid option. Then process the selection--knowing that the input is valid. If so, your loop is in the wrong place. EDIT2: My mistake... the bash man page says that the select construct repeatedly asks for valid input. So you can probably safely ignore my earlier edit. |
Quote:
and i ve edited Code:
if [ "$name" = "" ]; then but what should I edit the Code:
while [ "$guess" = "$name" ]; do |
It depends on what you want the script to do. ;)
If you just want to try what you have, one solution is to put: Code:
name="nomatch" |
If you intend to run it only once, then remove the last while and done pair.
OK |
Thanks! Dark_Helmet, AnanthaP. It works when I add name="nomatch"
|
Quote:
@Vi_rod - placing the if outside the loop will also not help you as once you enter another number, correct or not, 'name' will still not be populated and the issue continues. I would suggest placing your 'if' in the select loop, something like: Code:
select name in A B C |
All times are GMT -5. The time now is 01:57 PM. |