?
Solved

a simple csh script

Posted on 2008-09-29
7
Medium Priority
?
445 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 800 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
How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

 

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
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…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

765 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