The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Permission Reset? coopns OS X (Apple) 3 11-12-2008 03:45 PM
How to convert byteArray variables to HexaString variables for Linux? ritesh_163 High Level Programming 2 08-11-2008 12:55 AM
I would like to reset my password matrixmadhan Post Here to Contact Site Administrators and Moderators 5 04-30-2007 11:46 PM
How Do I Reset An Ssh Port PCTECH UNIX for Dummies Questions & Answers 3 01-04-2005 05:57 PM
System Reset s_aamir UNIX for Advanced & Expert Users 2 03-11-2002 05:15 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 06-17-2009
mutex1 mutex1 is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 4
How to check & reset variables

Hi,

I'm dealing with a small problem here that I can't seem to overcome by myself. Any help would be greatly appreciated

Basically, I have three variables, EXTSUB1, EXTSUB2 and EXTSUB3. These variables carry a file the user provides. What I need is to check each of the variables and if the specific variables carries a file with a specific extension, then reset that variable. I currently have the following but would like to reduce this code, maybe even do it in one go for all three variables...


Code:
# Check file extensions and if they match the
# defined ones, reset the specific variable

case "${EXTSUB1##*.}" in
            ass|ASS|idx|IDX|sub|SUB|sup|SUP|ssa|SSA)
             echo
             echo "-> Subtitle format '${EXTSUB1##*.}' not supported!"
             echo "-> Skipping import..."
             EXTSUB1=
             ;;
esac
case "${EXTSUB2##*.}" in
             ass|ASS|idx|IDX|sub|SUB|sup|SUP|ssa|SSA)
             echo
             echo "-> Subtitle format '${EXTSUB2##*.}' not supported!"
             echo "-> Skipping import..."
             EXTSUB2=
             ;;
esac
case "${EXTSUB3##*.}" in
               ass|ASS|idx|IDX|sub|SUB|sup|SUP|ssa|SSA)
               echo
               echo "-> Subtitle format '${EXTSUB3##*.}' not supported!"
               echo "-> Skipping import..."
               EXTSUB3=
               ;;
esac

Any better way of doing this with smaller code?

Thanks

-----------------------------------

OK, so I found away to use arrays for the job... Currently I have the following and it seems to work after some testing.


Code:
            for i in {1..3}; do
			if [ ! -z "${EXTSUB[$i]}" ]; then
				case "${EXTSUB[$i]##*.}" in
					idx|IDX|sub|SUB|sup|SUP|ass|ASS|SSA|SSA|ttxt|TTXT)
					echo
					echo "-> Subtitle format '$(echo ${EXTSUB[$i]##*.} | tr '[:lower:]' '[:upper:]')' not supported by OGM!"
					echo "-> Skipping import of '${EXTSUB[$i]}'"
					EXTSUB[$i]=
					;;
				esac
			fi
		done


Last edited by mutex1; 06-17-2009 at 03:01 PM..
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:22 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0