Results 1 to 10 of 11
Is it possible to set a variable for a few lines of echo ?
After user enter a file name, the user will be asked to continue or not, if ...
- 10-06-2007 #1Just Joined!
- Join Date
- Oct 2007
- Posts
- 8
How to loop inside the case ?
Is it possible to set a variable for a few lines of echo ?
After user enter a file name, the user will be asked to continue or not, if user press enter with no input which is * option in the case, i want the user be re-asked the same case menu which is
Any idea ?Code:echo "You just entered file name: [$filename]" echo "# Do you wish to enter another file name ?" echo "" echo "# Choices:-" echo "# ---------" echo "# y/Y - Yes, I want to continue." echo "# n/N - No, show me the last file name I entered!" echo -n "# Please enter your choice: " read choice
Full Code
Code:status=yes while [ "$status" = yes ] do echo -n "# Please enter file name: " read filename if [$filename = ""] then echo "# [Error] No Input!" echo "# Please run this script again." exit 1 else echo "You just entered file name: [$filename]" echo "# Do you wish to enter another file name ?" echo "" echo "# Choices:-" echo "# ---------" echo "# y/Y - Yes, I want to continue." echo "# n/N - No, show me the last file name I entered!" echo -n "# Please enter your choice: " read choice case $choice in y) status=yes ;; n) status=no echo "" echo "# Your last file name entered is : [$filename]" ;; Y) status=yes ;; N) status=no echo "" echo "# Your last file name entered is : [$filename]" ;; *) $repeat ;; esac shift fi done
Last edited by kahpeng; 10-06-2007 at 09:43 PM. Reason: Code Updated!
- 10-06-2007 #2forum.guy
- Join Date
- May 2004
- Location
- arch linux
- Posts
- 18,095
Is this homework/classwork?
oz
→ new members/users: read this first | new member faq
→ no private messages requesting computer support - post them on the forums!
→ please use the "report post" button to alert our forum admins to problematic posts rather than responding to them yourself.
- 10-06-2007 #3Just Joined!
- Join Date
- Oct 2007
- Posts
- 8
hi there ozar, i'm just doing exercise, try 2 improve n learn more in linux programming. am i asking silly questions to you ?
- 10-06-2007 #4forum.guy
- Join Date
- May 2004
- Location
- arch linux
- Posts
- 18,095
No, it's against the forum rules to post homework/classwork questions:
http://www.linuxforums.org/forum/lin...ums-rules.htmloz
→ new members/users: read this first | new member faq
→ no private messages requesting computer support - post them on the forums!
→ please use the "report post" button to alert our forum admins to problematic posts rather than responding to them yourself.
- 10-06-2007 #5Just Joined!
- Join Date
- Oct 2007
- Posts
- 8
ozar, sorry about that, i don't know. even if i post the code and ask some comment from others also can't ? i need someone to correct if i do wrong, i want to learn >.<
- 10-06-2007 #6forum.guy
- Join Date
- May 2004
- Location
- arch linux
- Posts
- 18,095
It's generally okay to post your code explaining what you've done to solve the problem yourself. People will often give clues and/or nudges to get you going.
It's not okay to post questions looking for specific answers to homework/classwork questions.
oz
→ new members/users: read this first | new member faq
→ no private messages requesting computer support - post them on the forums!
→ please use the "report post" button to alert our forum admins to problematic posts rather than responding to them yourself.
- 10-06-2007 #7Just Joined!
- Join Date
- Oct 2007
- Posts
- 8
okay, I understand, maybe the way I post is not correct.
So, this topic still consider "okay" or "not okay" ? Anyway, I changed my code while I was looking back at this topic, hope you don't close this topic as well. I added some error checking to my original code but need some advise to continue on.
Please do let me know if I can continue post my modified code in this topic, thanks for explaining about what the rules. Maybe my 1st post was confusing to you, I don't mean to ask for answer, I wanted to know if there's any other solution other than awk, I did reading sed stuff & etc, you might think I'm posting question for answers only, sorry about that
Cheers.
- 10-06-2007 #8forum.guy
- Join Date
- May 2004
- Location
- arch linux
- Posts
- 18,095
Yeah, you'll probably be okay as long as you don't ask for specific answers, or expect someone to provide the solutions for you.
The forum rules are enforced at each moderator's discretion, so I can't speak for all mods.
Have fun with Linux, and good luck with your Linux course.
oz
→ new members/users: read this first | new member faq
→ no private messages requesting computer support - post them on the forums!
→ please use the "report post" button to alert our forum admins to problematic posts rather than responding to them yourself.
- 10-06-2007 #9
May be something like this:
Code:status=yes while [ "$status" = yes ] do [ "$invalid" ]||{ echo -n "# Please enter file name: " read filename;} if [ -z "$filename" ] then echo "# [Error] No Input!" echo "# Please run this script again." exit 1 else [ "$invalid" ]||{ echo "You just entered file name: [$filename]" echo "# Do you wish to enter another file name ?" echo "" echo "# Choices:-" echo "# ---------" echo "# y/Y - Yes, I want to continue." echo "# n/N - No, show me the last file name I entered!";} echo -n "# Please enter your choice: ";unset invalid read choice case $choice in [Yy]) status=yes ;; [Nn]) status=no echo "" echo "# Your last file name entered is : [$filename]" ;; *) echo "# You have to make a choice.";invalid=y ;; esac fi done
- 10-06-2007 #10Just Joined!
- Join Date
- Oct 2007
- Posts
- 8
thanks radoulov, btw can i know -z purpose inside
the if statement ? Is it to check whether the variable is empty ?Code:if [ -z "$filename" ]


Reply With Quote
