[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

a simple csh script

Posted on 2008-09-29
7
Medium Priority
?
448 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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 

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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

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…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

656 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