Sponsored Content
Full Discussion: Case loop condition
Top Forums Shell Programming and Scripting Case loop condition Post 302779143 by amazigh42 on Tuesday 12th of March 2013 09:09:28 AM
Old 03-12-2013
Quote:
Originally Posted by Chubler_XL
Put EC= as first line of your function,
Replace each of your red text above with EC=1
and put [ "$EC" ] && exit $EC as the last line of your function

or try [ "$EC" ] as the last line and call the function like this:

Code:
if g1 $DATE $HOUR $MIN
then
     echo "Errors found in date/time - exiting now" >&2
     exit 1
fi

Thank you Chubler_XL
It doesn't work, i have this error
Code:
syntax error near unexpected token `"$EC"'

---------- Post updated at 08:09 AM ---------- Previous update was at 07:59 AM ----------

Quote:
Originally Posted by Corona688
Well, since it's in a function, you have a few easy-outs for that. You could return early for good cases, and have bad cases return error outside:
Code:
g1 () {
        case "$1" in
        A)
                return 0 # No error
                ;;
       ... # Many error checks which don't return
       esac

       echo "Some sort of error happened"
       return 1
}

Thanks Corona688 for this alternative.
I did not understand everything. Please, can you integrate your code in mine Y

Code:
g1() {
case "$1" in
([E,F,Q,P][A,C,S][A,I,V,P][D,R,T,V])
  # RAS, OK !
  ;;
(*)
  echo 'Fatal, $1 eq '"'$1'"', Bad context' >&2
exit=1
  ;;
esac

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Testing For Loop condition

How do I test the return condition in the script if no files are found: for file in `Find ${LANDING_FILE_DIR}${BTIME_FILENAME_PATTERN}` do ... .. done I want to capture the return code so I can echo the error or condition. Using if ] always returns zero no matter where it's placed. ... (4 Replies)
Discussion started by: mavsman
4 Replies

2. Shell Programming and Scripting

condition inside a for loop

I have a for loop in my script as shown below. for file_path in $file_list ; do ........my code .......... ...... done Can i restrict the number of files parsing to the variable file_path as 50? That is, even if I have some 100 files in file_list, I need to take only 50 files for... (7 Replies)
Discussion started by: Vijay06
7 Replies

3. Shell Programming and Scripting

if condition in a while loop

Gurus, I need to read a line from a file and strip the characters from it and compare the stripped value with the value I pass to the script while executing it. Below is the code for the same. But when i execute the code, it is throwing an error. #!/bin/ksh . /home/.i_env ... (14 Replies)
Discussion started by: svajhala
14 Replies

4. Shell Programming and Scripting

Use of -z in while loop condition

Hi, Could you please tell what is the meaning of -z in while loop condition. For example, while ; do echo "*** Enter the age " readage (3 Replies)
Discussion started by: vidyaj
3 Replies

5. Shell Programming and Scripting

Help With Loop in Case Statement script

I am writing a bash script that asks the user for input and I need it to repeat until the user selects quit.. I dont know how to write the loop for it I searched all over but i still do not get it.. if anyone could help with this it would be greatly apprciated here is my script so far: #!... (2 Replies)
Discussion started by: Emin_Em
2 Replies

6. Shell Programming and Scripting

Conversion from Upper Case to Lower Case Condition based

Hello Unix Gurus : It would be really appreciative if can find a solution for this . I have records in a file . I need to Capitalize the records based on condition . For Example i tried the following Command COMMAND --> fgrep "2000YUYU" /export/home/oracle/TST/data.dat | tr '' ''... (12 Replies)
Discussion started by: tsbiju
12 Replies

7. UNIX for Advanced & Expert Users

Lower case test condition

I want to locate directories that are upper, lower or have both upper and lower cases. What I have is: find /tmp/$var2 -type d' " ); && echo "host case is incorrect" || echo "host case is correct" This actually is part of a larger script and it does work but the problem is that it... (3 Replies)
Discussion started by: newbie2010
3 Replies

8. Shell Programming and Scripting

While Loop with if else condition

Hi, I was trying to write a shell script which reads csv file and sends mail in html format along with tables. Hope i have completed 1st part , but while sending mail i was trying to highlight some rows in the table based on the egrep outcome. If the string exists in line/INPUT, i am trying to... (4 Replies)
Discussion started by: varmas424
4 Replies

9. Linux

How to use a case stmt in a for loop?

How can I merge the move statements with the "FOR" loop to do a move of a file right after it zips it and not wait until all of the files are zipped to move all outisde the for loop. Here is my current code: for file in `ls -rt $svdumpdir/* | grep -v '.gz$' | grep '.gtt$' ` do echo... (8 Replies)
Discussion started by: mrn6430
8 Replies

10. Shell Programming and Scripting

Case sensitive in If loop .

Hi All, select app from the menu: ABC DEF GHI JKL ALL # ALL will select all the apps in the menu echo "Enter your option" read option; if then <execute the below command> elif # option is the 1 selection from menu...not ALL <execute the below command> else (14 Replies)
Discussion started by: Devaraj A
14 Replies
All times are GMT -4. The time now is 01:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy