Solved

a simple csh script

Posted on 2008-09-29
7
444 Views
Last Modified: 2013-12-26
I am looking for an example of csh script to test the input is a positive integer. Any input can help!!! Thanks!

My one didn't work
--------------------------
echo -n "Please enter a positive integer "
set input=$<
if ($input contains '-' || $input contains '.') then
    echo "wrong input"
else
   echo "input accepted"
endif
---------------------------
my problem is that I don't know how to grep the $input whether or not has a symbol minus sign i.e. '-' or decimal sign i.e. '.'
0
Comment
Question by:guochu
[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
  • 3
  • 3
7 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 22599543
if ( $input =~ *[.-]* ) then
0
 

Author Comment

by:guochu
ID: 22599959
it won't work if the input is abc :(
0
 
LVL 84

Accepted Solution

by:
ozo earned 200 total points
ID: 22600460
abc does not have a  minus sign i.e. '-' or decimal sign i.e. '.'
if you want o disallow anything other than digits, you might do
if ( $input =~ *[\!-/:-~]* ) then
0
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 

Author Comment

by:guochu
ID: 22600874
Work like a charm!!! Thanks! Can you explain [\!-/:-~] a little bit please?
0
 

Author Comment

by:guochu
ID: 22602119
Hello ozo, please explain a little bit!
0
 
LVL 84

Expert Comment

by:ozo
ID: 22602137
[^0-9] was failing in my csh when there was a * in front of it, so I used [\!-/:--~]  instead, which included the printable non-digits
0

Featured Post

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
Utilizing an array to gracefully append to a list of EmailAddresses
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

724 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