Solved

a simple csh script

Posted on 2008-09-29
7
440 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need to learn promise API 2 51
Linux Scripting 3 122
A script to extract the important data and calculate if the amounts are correct 12 67
AD Cleanup by EmployeeID 11 48
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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 how to dynamically set the form action using jQuery.

777 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