TCSH user input error checking


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting TCSH user input error checking
# 1  
Old 12-29-2012
TCSH user input error checking

This was taken down recently because it appeared to be homework, but it isn't. It's for a script I am working on at work. Thanks for the help.

How do you check that user inputs (arguments 1 and 2) are both numbers and are at least 5 digits in length?
# 2  
Old 12-30-2012
This is one way:

Code:
#!/usr/bin/tcsh
# Script: test.tcsh

set number = $1
echo $number
if ( $number =~ [0-9][0-9][0-9][0-9][0-9] ) then
  echo Parameter is a number
else
  echo Parameter is not a number OR is not 5 digits
endif


$ test.tcsh 12345
12345
Parameter is a number

$ test.tcsh 99
99
Parameter is not a number OR is not 5 digits

$ test.tcsh adf
adf
Parameter is not a number OR is not 5 digits

# 3  
Old 12-31-2012
bash

Hey,

BASH version is,

Code:
if [[ ${#1} -ge 5 && ${#2} -ge 5 && ! $1 =~ "[^0-9]" && ! $2 =~ "[^0-9]" ]];
then
   echo "True"
   # Do your stuff here.
fi

Cheers,
RangaSmilie

Last edited by rangarasan; 12-31-2012 at 06:22 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Checking the user input in perl for characters and length

My question is basically as the title says. How can I check a user inputted string is only certain characters long (for example, 3 characters long) and how do I check a user inputted string only contains certain characters (for example, it should only contain the characters 'u', 'a', 'g', and 'c')... (4 Replies)
Discussion started by: Eric1
4 Replies

2. Shell Programming and Scripting

TCSH user input checks

I would like to check user input for arguments 1 and 2 for my Solaris TCSH script for the following: 1. That both user input arguments are numbers. 2. That they are both at least 5 digits. Thanks for the help. (1 Reply)
Discussion started by: thibodc
1 Replies

3. Shell Programming and Scripting

How to get the user input recursively until the user provides valid input

Hi, echo "Enter file name of input file list along with absolute path : " read inputFileList if then for string in `cat inputFileList` do echo $string done else echo " file does not exist" fi From the above code, if the user enters a invalid file... (1 Reply)
Discussion started by: i.srini89
1 Replies

4. Shell Programming and Scripting

how to prompt the user to enter an array in tcsh

Hello, I am writing a script that requires the user to enter a string of numbers: ex: 134 345 865 903 This command only allows for one variable to be entered: set "var" = $< and than once I got the array I want to change it to a list with each input on a different line: ... (1 Reply)
Discussion started by: smarones
1 Replies

5. Programming

Checking columns in SQL, comparing user input and sizes.

I'm writing a KSH shell script that's using SQL though DB2. If I have a table defined and populated db2 "create table tb(num int,letter char(4))" db2 "insert into tb values(111,a) db2 "insert into tb values(112,b) db2 "insert into tb values(111,c) How can I check if a letter user... (0 Replies)
Discussion started by: busdude
0 Replies

6. UNIX for Advanced & Expert Users

Remote commands fail for tcsh user

I'm more familiar with bash/ksh that csh/tcsh. With that said, I recently ran across a problem with tcsh. Our system admin recently installed purify on our solaris 8 system. In order to use purify you have to execute a Rational script in order to setup the paths and some environment variables... (3 Replies)
Discussion started by: sszd
3 Replies

7. Shell Programming and Scripting

tcsh and user input

Here is my script: echo "var 1:" read varone echo "$varone" When I run in via ksh the script runs successfully. However when I run it via tcsh I get "varone: Undefine variable" Does the name command not work with tcsh or do I need some additional modification? Is there a way to get... (1 Reply)
Discussion started by: bonesy
1 Replies

8. Shell Programming and Scripting

tcsh user failed to call library in ksh program

Hi folks, I'm trying to organize functions in my ksh program into libraries. If I run my program as any ksh user it will succeed. Only when I run my program as tcsh user (i.e oracle) I failed. Example ======= The ksh code: tornado:/tmp # cat nir.ksh #! /bin/ksh cdromPath=`pwd`... (1 Reply)
Discussion started by: nir_s
1 Replies

9. Shell Programming and Scripting

TCSH.need help.take input during a while/end loop

I am writting a script in csh and I am blanking out on how I code in the ability to process user input in the middle of a while/end loop. while(1) args.. end it is a simple script, and I want to add hotkey functions, like q to quit, z to zero counters, etc.. Google has not been very... (1 Reply)
Discussion started by: seg
1 Replies
Login or Register to Ask a Question