Results 1 to 3 of 3
Hi, all.
I have a script that deletes mysql accounts from mysql.user. The user can either get confirmation per deletion with option -i or not. For example,
Code:
delete_acct -i ...
- 10-16-2008 #1Just Joined!
- Join Date
- Oct 2008
- Posts
- 11
terminal input for confirmation -i option
Hi, all.
I have a script that deletes mysql accounts from mysql.user. The user can either get confirmation per deletion with option -i or not. For example,
... says delete all user ids beginning with "a","b", or "c" and prompt the person at the terminal for each one. But again, -i is optional. Here's my script so far:Code:delete_acct -i ^[abc]
My problem is the inner part (which is similar to my problem in another post). I originally had an inner if statement but I was getting syntax errors. Embedding another if,else,fi was causing problems. I know that I can't use a for loop from my last post. I'm wondering if anyone has any advice on the best way to approach this problem.Code:while read userid; do if [ $flag="-i" ]; then print -n "Are you sure that you want to delete" $userid "?" read answer < /dev/tty if $answer="y" then delete $userid else exit 1 else mysql -BCNnqs --disable-pager -u<username> -p<password> <<EOF drop user '$userid'@'localhost'; quit EOF fi done < list_master
Thanks.
- 10-16-2008 #2Just Joined!
- Join Date
- Oct 2008
- Posts
- 11
flow control and nesting
Since I'm still at the top of the queue, I thought I'd that I'm using Ksh.
Also, I was thinking...
What I'm really looking for here is some guidance on flow control and nesting. I learned from a different post that you shouldn't nest for loops. But I'm finding in general that scripting (at least in ksh) is not intuitive. I keep wanting to do stuff like this:
Code:for arg; do if func $arg; then while arg; do if $arg="x" print "PASS 1: " $arg else print "PASS 2: " $arg fi done else print "FAIL: " $arg fi done
And it keeps failing. I get errors like "syntax error: `else' unexpected". If anyone knows how to explain this concept simply or can point me to a good reference on this specific topic, I would appreciate it.
Thanks.
- 10-17-2008 #3Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
Have you tried reading the ksh manpage? The one I have is quite clear on the syntax of loops and branches.


Reply With Quote