Sponsored Content
Top Forums Shell Programming and Scripting Check if the input is number or text? Post 302370370 by waso on Wednesday 11th of November 2009 08:02:07 AM
Old 11-11-2009
CPU & Memory Check if the input is number or text?

i have to check if is input number or text, i case that is text then exit script

exaple is hrere, but is not working

Code:
check_it()
{
    if [ "$1" != +([a-zA-Z]) ]
        then        
        if (( $1 > 0 && $1 < 13 )); 
            then
                echo "input number is ok"
        else
                echo "number not ok"
                exit 1
        fi
    else
      echo "just numbers please"
      exit 1
    fi
}

case $1 in
        0*)             echo "sorry, no leading zeroes"
                        exit 1;;
        "")             echo "input parameter is required"
                        exit 1;;
esac

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

What can i do to check that the input is all alphabet.. ?

What can i do to check that the input is all alphabet.. ? (4 Replies)
Discussion started by: XXXXXXXXXX
4 Replies

2. Shell Programming and Scripting

Check on Input

HI all, I would like to know how the user can be restricted for entering only the number and not characters in sheel scripts.. Suppose code is like this echo 'Enter the number' read Value Now user may enter 'a' as value... But i want to disallow him for entering characters other than... (3 Replies)
Discussion started by: dhananjaysk
3 Replies

3. UNIX for Dummies Questions & Answers

check the input

how to check whether a given input is a number or a string? (1 Reply)
Discussion started by: Shilpi
1 Replies

4. Shell Programming and Scripting

Bash : how do i check the user input and make sure is only chracter or only number ?

Bash : how do i check the user input and make sure is only character or only number ? (7 Replies)
Discussion started by: CheeSen
7 Replies

5. Shell Programming and Scripting

shell script to take input from a text file and perform check on each servers and copy files

HI all, I want to script where all the server names will be in a text file like server1 server2 server3 . and the script should take servernames from a text file and perform copy of files if the files are not present on those servers.after which it should take next servername till the end of... (0 Replies)
Discussion started by: joseph.dmello
0 Replies

6. UNIX for Dummies Questions & Answers

Check Column corresponding to input

I have a file which extracts data from an HTML file For Eg HTML file contains: New York;ABC;145;Yes;YES;No New York;BCD;113;Yes;YES;No New York;NAS;63;Yes;YES;No ------------------------ London-48;CBT;16;Yes;YES;No London-48;CME;17;Yes;YES;No London-48;EUR;52;Yes;YES;No... (7 Replies)
Discussion started by: newkid.7955
7 Replies

7. Shell Programming and Scripting

Check whether input is numeric

Hello there, find below for my code first: $pdp_asaba=`cat /tmp/temp_total | grep asaba | sed 's/*//g'` if ]] then pdp_asaba=0 fi $pdp_abuja=`cat /tmp/temp_total | grep abuja | sed 's/*//g'` if ]] then pdp_abuja=0 fi $pdp_ojota=`cat /tmp/temp_total | grep ojota | sed 's/*//g'` if ... (3 Replies)
Discussion started by: infinitydon
3 Replies

8. UNIX for Dummies Questions & Answers

Search String, Out matched text and input text for no match.

I need to search a string for some specific text which is no big deal using grep. My problem is when the search fails to find the text. I need to add text like "na" when my search does not match. I have tried this command but it does not work when I put the command in a loop in a bash script: ... (12 Replies)
Discussion started by: jojojmac5
12 Replies

9. Shell Programming and Scripting

awk to skip lines find text and add text based on number

I am trying to use awk skip each line with a ## or # and check each line after for STB= and if that value in greater than or = to 0.8, then at the end of line the text "STRAND BIAS" is written in else "GOOD". So in the file of 4 entries attached. awk tried: awk NR > "##"' "#" -F"STB="... (6 Replies)
Discussion started by: cmccabe
6 Replies

10. Shell Programming and Scripting

Search last column of INPUT.txt in TABLEs text and add correspond columns to INPUT.txt

Hi dears i use bash shell i have INPUT.txt like this number of columns different in one some row have 12 , some 11 columns see last column INPUT.txt CodeGender Age Grade Dialect Session Sentence Start End Length Phonemic Phonetic 63 M 27 BS/BA TEHRANI 3 4 298320 310050... (2 Replies)
Discussion started by: alii
2 Replies
EXIT(3) 								 1								   EXIT(3)

exit - Output a message and terminate the current script

SYNOPSIS
void exit ([string $status]) DESCRIPTION
void exit (int $status) Terminates execution of the script. Shutdown functions and object destructors will always be executed even if exit is called. exit is a language construct and it can be called without parentheses if no $status is passed. PARAMETERS
o $status - If $status is a string, this function prints the $status just before exiting. If $status is an integer, that value will be used as the exit status and not printed. Exit statuses should be in the range 0 to 254, the exit status 255 is reserved by PHP and shall not be used. The status 0 is used to terminate the program successfully. Note PHP >= 4.2.0 does NOT print the $status if it is an integer. RETURN VALUES
No value is returned. EXAMPLES
Example #1 exit example <?php $filename = '/path/to/data-file'; $file = fopen($filename, 'r') or exit("unable to open file ($filename)"); ?> Example #2 exit status example <?php //exit program normally exit; exit(); exit(0); //exit with an error code exit(1); exit(0376); //octal ?> Example #3 Shutdown functions and destructors run regardless <?php class Foo { public function __destruct() { echo 'Destruct: ' . __METHOD__ . '()' . PHP_EOL; } } function shutdown() { echo 'Shutdown: ' . __FUNCTION__ . '()' . PHP_EOL; } $foo = new Foo(); register_shutdown_function('shutdown'); exit(); echo 'This will not be output.'; ?> The above example will output: Shutdown: shutdown() Destruct: Foo::__destruct() NOTES
Note Because this is a language construct and not a function, it cannot be called using variable functions. Note This language construct is equivalent to die(3). SEE ALSO
register_shutdown_function(3). PHP Documentation Group EXIT(3)
All times are GMT -4. The time now is 12:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy