Visit Our UNIX and Linux User Community


i get stuck with this shell script code

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions i get stuck with this shell script code
# 1  
Old 08-24-2009
i get stuck with this shell script code

i get stuck here . Anyone could check my work?
the user type a group of upper case letters at a time with 0 at the end. Find and display the first letter in alphabetic order.

For example, input of F, G, K, S, U, G, D, Q, P , the result should be D
Any invalid input character (eg. #, $, 3, a, etc.) should cause an error message and be ignored.

echo "please enter an alphabet"
input3=1
echo "" > temp
while [ "$input3" != "0" ]; do
read input3
echo $input3 > check
if [ "$input3" != "0" ]; then
if [ check1=`grep -w "[A-Z]" check ]; then
echo $input3 >> temp
else
echo input should be upper case alphabet
fi
fi
done
grep -w "[A-Z]" temp > temp1
echo the first letter in alphabetic order is `sort temp1 | head -1`;;
# 2  
Old 08-24-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

---------- Post updated at 10:51 AM ---------- Previous update was at 09:11 AM ----------

Code:
#!/usr/bin/ksh

TMP="bla"

# Clean up old temp file
clean_up()
{
        if [[ -e $TMP ]]; then
                rm $TMP
        fi
}

clean_up

echo "Enter one upper case character per line and hit enter; to stop enter a zero."

while :; do
        read INPUT
        case $INPUT in
                [A-Z])          echo $INPUT >> $TMP
                                ;;
                0)              echo '------ OUTPUT ------'
                                sort $TMP| uniq| head -1
                                break
                                ;;
                *)              echo "no upper case letter and/or more than 1 character!"
                                ;;
        esac
done

clean_up

exit 0

# 3  
Old 08-25-2009
thanks for your help....love you so much!!keke

---------- Post updated 08-25-09 at 02:21 AM ---------- Previous update was 08-24-09 at 09:36 AM ----------

hi Zaxxon!
your code still work with lower case characters , can you check it again!?
# 4  
Old 08-25-2009
Works on my box:

Code:
Enter one upper case character per line and hit enter; to stop enter a zero.
3
no upper case letter and/or more than 1 character!
d
no upper case letter and/or more than 1 character!
F
s
no upper case letter and/or more than 1 character!
S
h
no upper case letter and/or more than 1 character!
$
no upper case letter and/or more than 1 character!
p
no upper case letter and/or more than 1 character!
P
0
------ OUTPUT ------
F

I guess you did not use ksh - I have the same problem like you on bash. Not sure why though. When using ksh like in the shebang (#!/usr/bin/ksh) all is fine. Maybe someone else knows why, sorry.



Update:
Found a way in bash - change the line inside the case/esac to:
Code:
                [A-Z])          echo $INPUT >> $TMP
# to
                [[:upper:]])          echo $INPUT >> $TMP


Last edited by zaxxon; 08-25-2009 at 05:42 AM.. Reason: update
# 5  
Old 08-25-2009
yeah! now i undertand my problem! thanks for your help.
# 6  
Old 08-25-2009
HOMEWORK CANNOT BE POSTED WITHOUT USING THE HOMEWORK TEMPLATE

Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.

Previous Thread | Next Thread
Test Your Knowledge in Computers #420
Difficulty: Medium
JavaScript supports much of the structured programming syntax from C (e.g., if statements, while loops, switch statements, do while loops, etc.).
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Checking LB status.. stuck in script syntax of code

#!/bin/ksh #This script will check status of load balancer in AIX servers from hopbox #Steps to do as folows : #Login to server #netstat -ani | grep <IP> #check if the output contains either lo0 OR en0 #if the above condition matches, validation looks good #else, send an email with impacted... (7 Replies)
Discussion started by: vinil
7 Replies

2. Shell Programming and Scripting

Error in script, STUCK :(

Hi All, I am beginner in scripting. I wrote a simple script to perform some task. It seem to have some error in command line, Kindly somebody help. Thanks #!/bin/bash date cd /home/poojasaxena/Desktop/CMS/script/DataMCMatch function pause(){ read -p "$*" } FILE=$1... (22 Replies)
Discussion started by: nrjrasaxena
22 Replies

3. Shell Programming and Scripting

stuck on first script with sed issue

Hi, I'm developing my first bash script and have made good progress but stuck at this point. I've run sed on a text file to extract some data and have saved it into a variable e.g. $blah the variable contains emails as follows e.g. <a@b.com> <b@c.com> I'm now trying to edit... (2 Replies)
Discussion started by: newb1000
2 Replies

4. Shell Programming and Scripting

Stuck in this shell script - please help

hi: I'm trying to write a shell script that recognizes all .txt files in all the subdirectories in my current directory. Let's say that i have a directory called Applications which consists of many subdirectories on mnay levels. i want the shell script to look for all .txt files that exist... (14 Replies)
Discussion started by: miss_dodi
14 Replies

5. Shell Programming and Scripting

korn shell display lenght problem!!! i got stuck on this

Using the KSH, write a shell script called display_by_length, which takes an absolute pathname to a directory and displays all ordinary files in the directory ordered by their length; for each file listed, display the name of the file and its length - nothing else. Extend this script to take an... (1 Reply)
Discussion started by: babuda0059
1 Replies

6. Shell Programming and Scripting

Script Stuck In Loop

Hi all! Im trying to get this script to check for folders in a year/month/day folder structure and if the day doesnt exist then it makes the day. It will also make sure all of the days before todays date exist as well. This script assumes that the month and year folder already exist. It works... (3 Replies)
Discussion started by: Grizzly
3 Replies

7. Shell Programming and Scripting

I am stuck in my script

Hi All I have script that find 777 dir with specific extension like .php .Now after finding all 777 directory i will place in httpd.conf using a directory directive ,Now i was not do that,if directory entry exitst in httpd.conf then script ignor it dont show me at stdout else if it dont find... (2 Replies)
Discussion started by: aliahsan81
2 Replies

8. UNIX for Dummies Questions & Answers

stuck with a script

Hi There I am pretty new to UNIX and have only been using it from a basic point of view,I now want to start using it and learning more , have got a whole lot of books and documentation from the web and am slowly learning.I have written a get script in windows :- lcd E:\MAIN\PRO\FILES\MAINDB... (1 Reply)
Discussion started by: FOCKER
1 Replies

9. Shell Programming and Scripting

simple script but am stuck

hey i am a bit stuck here. i just started work experience and i need to create a simple script which delete all files in a specify folder which are older then 2 days. :mad: i tried but it never works!!! anyone! i dont know much but unix since i mostly work on NT here but i dont wanna disapoint my... (2 Replies)
Discussion started by: GermanJulian
2 Replies

10. Shell Programming and Scripting

stuck on ksh script

hi, i need help to write script in korn shell that will display info. on system paging, system process table.system file table inf. thank you (1 Reply)
Discussion started by: neer45
1 Replies

Featured Tech Videos