Solved

KSH Script - Compare variable with expression

Posted on 2006-10-19
2
953 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

623 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