a simple csh script

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. '.'
guochuAsked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
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
 
ozoCommented:
if ( $input =~ *[.-]* ) then
0
 
guochuAuthor Commented:
it won't work if the input is abc :(
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
guochuAuthor Commented:
Work like a charm!!! Thanks! Can you explain [\!-/:-~] a little bit please?
0
 
guochuAuthor Commented:
Hello ozo, please explain a little bit!
0
 
ozoCommented:
[^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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.