Solved

a simple csh script

Posted on 2008-09-29
7
435 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
  • 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now