Solved

KSH Script - Compare variable with expression

Posted on 2006-10-19
2
946 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
List out all word 7 320
fizzArray2 challenge 1 91
building a service to accessed via telnet client, want colors ? 4 94
Not needed 13 120
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 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