Sponsored Content
Full Discussion: Check on Input
Top Forums Shell Programming and Scripting Check on Input Post 101794 by dhananjaysk on Monday 13th of March 2006 09:15:36 AM
Old 03-13-2006
Hi,

The code u send is working fine...
Now it is not giving an error expr : as non-numeric argument
I am working on Ksh

But if i wanna do following

$ User prompted -> Enter the number
$ He enters -> b

now instead of accepting 'b' ( as it is not an integer )
I want to clear that 'b' ...as follows and again prompt the user for entering the value

$ User prompted -> Enter the number
$ He enters -> b

( clear that 'b' or any character unless and until he enters integer )

$ User prompted -> Enter the number

Thanks..

Quote:
Originally Posted by blowtorch
What shell are you using? If you are using ksh, you can use typeset -i. Here's how:
Code:
$ typeset -i a
$ echo $a

$ a=a
$ echo $a
0
$ a=10
$ echo $a
10

A non-integer will be automatically set to 0.

- note: this is tested on FreeBSD.
 

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. 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

3. Shell Programming and Scripting

How to check for Input Redirection in my script?

All, I have a requirement to write a script where I check for Input redirection when the script was executed, based on which I handle my logic. Below is the example: my.script #! /bin/ksh # Not sure how to frame the if condition below if ; then echo "Input Redirected from a file" ... (7 Replies)
Discussion started by: bharath.gct
7 Replies

4. Programming

How to check an input variable

Suppose we have a simple situation, like the following C++ instructions: int x; cout << "Insert x: "; cin >> x; while ( x-- < 0 ) ; Of course, if it is written something different from an integer, the while loop shall not end. So, how can we check if the input x is of the right type? (2 Replies)
Discussion started by: Luke Bonham
2 Replies

5. Shell Programming and Scripting

Check input parameter

Hi all i need to check that if user has passed any input parameter while executing he shell script like ./test1.sh -a"-v" then do smothing if user execute the script without giving input paramater then ./test1.sh then do something how can we check this input parameter (6 Replies)
Discussion started by: aishsimplesweet
6 Replies

6. Shell Programming and Scripting

Input file check

Hi, I have a script which runs daily. It gets 3 input files test1,test2,test3. I want to do a validation in my script to make sure i have all the 3 files available before running. If any one of the file is missing i want to break the script. Could you please help me with this request. ... (1 Reply)
Discussion started by: Krrishv
1 Replies

7. Shell Programming and Scripting

To Check whether the Input is a Year or Not?

Hi Guys I have a Requirement that the input will be given and i have to check whether the input is a Year or not. For Example 2004,2009 and so on forth will be considered a year and anything else like 12:15 or else will not be. Have built the below Code set -x echo " Enter... (6 Replies)
Discussion started by: Ajesh
6 Replies

8. Shell Programming and Scripting

Check user input

Hi, I need my script to check if the user enters 3 values if not 5 values to my script and alert if the input has any other number of values. for example: ./myscript.sh 22 56 3221 - > correct ./myscript.sh 22 56 3221 45 777 -> correct ./myscript.sh 22 56 3221 45 -> incorrect Please... (6 Replies)
Discussion started by: mohtashims
6 Replies

9. 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

10. 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
READLINE_CALLBACK_HANDLER_INSTALL(3)					 1				      READLINE_CALLBACK_HANDLER_INSTALL(3)

readline_callback_handler_install - Initializes the readline callback interface and terminal, prints the prompt and returns immediately

SYNOPSIS
bool readline_callback_handler_install (string $prompt, callable $callback) DESCRIPTION
Sets up a readline callback interface then prints $prompt and immediately returns. Calling this function twice without removing the previ- ous callback interface will automatically and conveniently overwrite the old interface. The callback feature is useful when combined with stream_select(3) as it allows interleaving of IO and user input, unlike readline(3). PARAMETERS
o $prompt - The prompt message. o $callback - The $callback function takes one parameter; the user input returned. RETURN VALUES
Returns TRUE on success or FALSE on failure. Example #1 Readline Callback Interface Example <?php function rl_callback($ret) { global $c, $prompting; echo "You entered: $ret "; $c++; if ($c > 10) { $prompting = false; readline_callback_handler_remove(); } else { readline_callback_handler_install("[$c] Enter something: ", 'rl_callback'); } } $c = 1; $prompting = true; readline_callback_handler_install("[$c] Enter something: ", 'rl_callback'); while ($prompting) { $w = NULL; $e = NULL; $n = stream_select($r = array(STDIN), $w, $e, null); if ($n && in_array(STDIN, $r)) { // read a character, will call the callback when a newline is entered readline_callback_read_char(); } } echo "Prompting disabled. All done. "; ?> readline_callback_handler_remove(3), readline_callback_read_char(3), stream_select(3). PHP Documentation Group READLINE_CALLBACK_HANDLER_INSTALL(3)
All times are GMT -4. The time now is 07:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy