Sponsored Content
Full Discussion: validate number range
Top Forums Shell Programming and Scripting validate number range Post 63120 by zazzybob on Tuesday 22nd of February 2005 08:28:37 PM
Old 02-22-2005
A slight variation on bhargav's script to ensure that only numeric digits are passed, and symbols as well as letters are rejected....
Code:
#!/bin/sh

echo "Enter number"
read val

if echo $val | egrep '^[0-9]+$' >/dev/null 2>&1
then
  if [ $val -ge 1 -a $val -le 100 ]; then
     echo "OK"
  else
     echo "Out of range"
  fi
else
  echo "Not a number"
fi

exit 0

Cheers
ZB
This User Gave Thanks to zazzybob For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

PERL: Simple reg expr validate 6 digits number

Hi there! I'm trying to validate a simple 6 digits number with reg expr. I ONLY want 6 digits so when i type 7 digits the script should no validate the number. I've write this code: #!/usr/bin/perl while(<STDIN>){ if($_=~/\d{6}/){ print "Bingo!\n"; ... (2 Replies)
Discussion started by: BufferExploder
2 Replies

2. Shell Programming and Scripting

extract number range from a file

Hi Everyone, a.txt 1272904667;1272904737;1 1272904747;1272904819;1 1272904810;1272904857;1 1272904889;1272904926;1 1272905399;1272905406;1 1272905411;1272905422;1 if i want to get the record, when the a.txt 1st field is between 1272904749 and 1272905399, any simple way by using awk,... (1 Reply)
Discussion started by: jimmy_y
1 Replies

3. Shell Programming and Scripting

Number range for SSNs

Hi All. I have a file that has an ID Number field....some of the ID Numbers are actual SSNs. ...does anyone know the range that SSNs may be...this is what I have found so far poking around SSN info sites.... greater than 001-01-0000 and less than 770-00-0000. Does anyone know this to be... (1 Reply)
Discussion started by: lyoncc
1 Replies

4. Shell Programming and Scripting

Closest Number from a Range of Numbers

out of a range of numbers, how can i pick out the number that is the closest to any arbitrary/random number that a user supplies? say the range of numbers are between 1 - 90000. but that doesn't mean each number exist between 1 - 90000. the range of numbers could be for example: 1, 3, 4, 6,... (6 Replies)
Discussion started by: SkySmart
6 Replies

5. Shell Programming and Scripting

Range of number from 0.1 to 10.0

Is there a way to create a loop that will output number starting from 0.1 to 10.0 0.1 0.2 0.3 0.4 0.5 .. ... 10.0 This is what i tried. for i in {1..50}; do printf -v i '%02d' $i ; echo "$i"; done That will print 01 02 03 .. .. 50 (9 Replies)
Discussion started by: vietrice
9 Replies

6. Shell Programming and Scripting

If statement test against number range [0-9]

Is it possible to test against a varible within a ranges in a if statement. ex. if ];then echo "not in range" else echo "number within range" fi (8 Replies)
Discussion started by: leemalloy
8 Replies

7. Shell Programming and Scripting

Fill data if number range is given

Hi I want to get all numbers if number range is given as input. Eg: INPUT FILE 100-105 107 108-112 OUTPUT REQUIRED: 100 101 102 103 104 105 107 108 109 110 111 112 How can I do it using shell? :confused: Thanks in advance. (11 Replies)
Discussion started by: dashing201
11 Replies

8. Shell Programming and Scripting

Generating Random Number in certain range

Hi there I am trying to generate a random number between 40 and 70 using the shell here is my code so far and it keeps going above 70. all help much appreciated! comp=$(( RANDOM%70+40 )) echo $comp (4 Replies)
Discussion started by: faintingquiche
4 Replies

9. UNIX for Dummies Questions & Answers

Using sed to replace a range of number

Trying to use SED to replace numbers that fall into a range but can't seem to get the logic to work and am wondering if SED will do this. I have a file with the following numbers 3 26 20 5. For the numbers that are greater than zero and less than 25, SED would add the word range after the... (7 Replies)
Discussion started by: jimmyf
7 Replies

10. Shell Programming and Scripting

Detect continuous number as range

I have 100k data like this bellow , i want to group data to range 171 172 173 174 175 176 179 182 183 187 188 189 1900 1901 1903 1904 1905 1906 (10 Replies)
Discussion started by: before4
10 Replies
DB2_GET_OPTION(3)							 1							 DB2_GET_OPTION(3)

db2_get_option - Retrieves an option value for a statement resource or a connection resource

SYNOPSIS
string db2_get_option (resource $resource, string $option) DESCRIPTION
Retrieves the value of a specified option value for a statement resource or a connection resource. PARAMETERS
o $resource - A valid statement resource as returned from db2_prepare(3) or a valid connection resource as returned from db2_connect(3) or db2_pconnect(3). o $option - A valid statement or connection options. The following new options are available as of ibm_db2 version 1.6.0. They provide use- ful tracking information that can be set during execution with db2_get_option(3). Note Prior versions of ibm_db2 do not support these new options. When the value in each option is being set, some servers might not handle the entire length provided and might truncate the value. To ensure that the data specified in each option is converted correctly when transmitted to a host system, use only the characters A through Z, 0 through 9, and the underscore (_) or period (.). o $userid - SQL_ATTR_INFO_USERID - A pointer to a null-terminated character string used to identify the client user ID sent to the host database server when using DB2 Connect. Note DB2 for z/OS and OS/390 servers support up to a length of 16 characters. This user-id is not to be confused with the authentication user-id, it is for identification purposes only and is not used for any authorization. o $acctstr - SQL_ATTR_INFO_ACCTSTR - A pointer to a null-terminated character string used to identify the client accounting string sent to the host database server when using DB2 Connect. Note DB2 for z/OS and OS/390 servers support up to a length of 200 characters. o $applname - SQL_ATTR_INFO_APPLNAME - A pointer to a null-terminated character string used to identify the client application name sent to the host database server when using DB2 Connect. Note DB2 for z/OS and OS/390 servers support up to a length of 32 characters. o $wrkstnname - SQL_ATTR_INFO_WRKSTNNAME - A pointer to a null-terminated character string used to identify the client workstation name sent to the host database server when using DB2 Connect. Note DB2 for z/OS and OS/390 servers support up to a length of 18 characters. The following table specifies which options are compatible with the available resource types: Resource-Parameter Matrix +-----------+--------------------------+---+---+---+ | Key | | | | | | | | | | | | | Value | | | | | | | | | | | | Resource Type | | | | | | | | | | +-----------+--------------------------+---+---+---+ |Connection | | | | | | | | | | | | | Statement | | | | | | | | | | | | Result Set | | | | | | | | | | | userid | | | | | | | | | | | | | | | | | | | SQL_ATTR_INFO_USERID | | | | | | | | | | | | X | | | | | | | | | | | | X | | | | | | | | | | | | - | | | | | | | | | | | acctstr | | | | | | | | | | | | | | | | | | | SQL_ATTR_INFO_ACCTSTR | | | | | | | | | | | | X | | | | | | | | | | | | X | | | | | | | | | | | | - | | | | | | | | | | | applname | | | | | | | | | | | | | | | | | | | SQL_ATTR_INFO_APPLNAME | | | | | | | | | | | | X | | | | | | | | | | | | X | | | | | | | | | | | | - | | | | | | | | | | |wrkstnname | | | | | | | | | | | | | | | | | | | SQL_ATTR_INFO_WRKSTNNAME | | | | | | | | | | | | X | | | | | | | | | | | | X | | | | | | | | | | | | - | | | | | | | | | | +-----------+--------------------------+---+---+---+ RETURN VALUES
Returns the current setting of the connection attribute provided on success or FALSE on failure. EXAMPLES
Example #1 Setting and retrieving parameters through a connection resource <?php /* Database Connection Parameters */ $database = 'SAMPLE'; $user = 'db2inst1'; $password = 'ibmdb2'; /* Obtain Connection Resource */ $conn = db2_connect($database, $user, $password); echo "Client attributes passed through connection string: "; /* Create the associative options array with valid key-value pairs */ /* Assign the attributes through connection string */ /* Access the options specified */ $options1 = array('userid' => 'db2inst1'); $conn1 = db2_connect($database, $user, $password, $options1); $val = db2_get_option($conn1, 'userid'); echo $val . " "; $options2 = array('acctstr' => 'account'); $conn2 = db2_connect($database, $user, $password, $options2); $val = db2_get_option($conn2, 'acctstr'); echo $val . " "; $options3 = array('applname' => 'myapp'); $conn3 = db2_connect($database, $user, $password, $options3); $val = db2_get_option($conn3, 'applname'); echo $val . " "; $options4 = array('wrkstnname' => 'workstation'); $conn4 = db2_connect($database, $user, $password, $options4); $val = db2_get_option($conn4, 'wrkstnname'); echo $val . " "; echo "Client attributes passed post-connection: "; /* Create the associative options array with valid key-value pairs */ /* Assign the attributes after a connection is made */ /* Access the options specified */ $options5 = array('userid' => 'db2inst1'); $conn5 = db2_connect($database, $user, $password); $rc = db2_set_option($conn5, $options5, 1); $val = db2_get_option($conn5, 'userid'); echo $val . " "; $options6 = array('acctstr' => 'account'); $conn6 = db2_connect($database, $user, $password); $rc = db2_set_option($conn6, $options6, 1); $val = db2_get_option($conn6, 'acctstr'); echo $val . " "; $options7 = array('applname' => 'myapp'); $conn7 = db2_connect($database, $user, $password); $rc = db2_set_option($conn7, $options7, 1); $val = db2_get_option($conn7, 'applname'); echo $val . " "; $options8 = array('wrkstnname' => 'workstation'); $conn8 = db2_connect($database, $user, $password); $rc = db2_set_option($conn8, $options8, 1); $val = db2_get_option($conn8, 'wrkstnname'); echo $val . " "; ?> The above example will output: Client attributes passed through connection string: db2inst1 account myapp workstation Client attributes passed post-connection: db2inst1 account myapp workstation SEE ALSO
db2_connect(3), db2_cursor_type(3), db2_exec(3), db2_set_option(3), db2_pconnect(3), db2_prepare(3). PHP Documentation Group DB2_GET_OPTION(3)
All times are GMT -4. The time now is 10:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy