Solved

KSH Script - Compare variable with expression

Posted on 2006-10-19
2
941 Views
Last Modified: 2013-12-26
I do not know if this is the best way.  This is the beginning of building a bigger script. I am trying to see if a variable is a digit (3 digits between 0-9) in a ksh script. Do I need to verify the variable before I get into the IF statement?

for list in `grep -l '\*\*\*\*\*' ??????`
do
    varLine=`head -l -n 1 $list`
    varDocType=`echo "$varLine" | cut -c23-25`
    if [ varDocType -eq +([0-9]) ]
    then
        echo "Filename=$list Document Type=$varDocType"
    else
        echo "Not Correct Type"
    fi
done
0
Comment
Question by:TomTinsley
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 250 total points
ID: 17769113
case $varDocType in
[0-9][0-9][0-9])
   echo "Filename=$list Document Type=$varDocType";;
*)
        echo "Not Correct Type";;
esac
0
 
LVL 3

Author Comment

by:TomTinsley
ID: 17769151
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now