Reading numbers thru shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading numbers thru shell
# 1  
Old 01-18-2008
Reading numbers thru shell

Dear pal,

I want to read only numbers thru a shell script,
If user is trying to enter character it should block that ...

Pls help to me find out a solution
# 2  
Old 01-18-2008
example code snippet:

Code:
#  x="q"; while [ `echo $x | grep  "[^0-9]"` ]; do read x; done
hello
123g
12

#  echo $x
12

# 3  
Old 04-14-2009
read integer 2>/dev/null

until [[ $integer = +([0-9]) ]]
do
read integer 2>/dev/null
done
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Floating Point Numbers in c shell!

I have started using bash but this script which I am working on it, is in c chell. So here is my simple problem: set x = 0.4124\0.234 echo $x 0.4124.0.234 Same operation in Bash gives me correct result in my terminal. So there is something with my c shell that is causing this behaviour.... (8 Replies)
Discussion started by: dixits
8 Replies

2. Shell Programming and Scripting

Using Fractional Numbers in Shell Variables

Hello everyone, Before I state my problem I would like to inform you that this is not an assignment. I'm just trying to learn some shell programming in my free time. I'm trying to write a parking fee calculator. But I don't seem to be able to use fractional numbers. Could you please advice... (6 Replies)
Discussion started by: iwant2learn
6 Replies

3. Shell Programming and Scripting

Reading a table from shell

i want to do something like this from shell, for any user without having to enter any passwords i want to store the value in the option_value column into a variable select option_value from `$databasename`.`wp_options` where option_name="template"; what is the command i should use? ... (0 Replies)
Discussion started by: vanessafan99
0 Replies

4. Shell Programming and Scripting

How is shell reading this?

Morning (or evening) all. I have some code: tput cup 21 1 ; echo "Press ENTER to continue. . . " read prompt Nowhere do I see "prompt" define. How is shell reading prompt? I'm so used to writing code in SAS, COBOL, etc where everything has to be defined. Thank you (2 Replies)
Discussion started by: Ccccc
2 Replies

5. Shell Programming and Scripting

Shell script to check numbers!

Hello All, I have 3 types of files. The names of which starts with P,I,M like P********* D********* M********* now I need to do some operations witht hese files.. so if file name starts with P or p then do the operation for P file... fi else (20 Replies)
Discussion started by: smarty86
20 Replies

6. Shell Programming and Scripting

reverse ':' separated numbers in a shell script

I want to reverse a the following: 00:11:22:33:44:55 I currently use something like below to pass it as is. But now I want the same script to reverse the above and pass it to ethtool. // psuedo code i=0 skip=0 for m in $@ do if then skip=1 ... (1 Reply)
Discussion started by: bhanu.nani
1 Replies

7. UNIX for Dummies Questions & Answers

How to Convert Strings into Numbers under C-Shell?

I tried something like: set test3 = (4.985e-10 5.130e-10 5.486e-10 6.023e-10 7.015e-10) set test4 = (4.869e-10 5.010-10 5.363e-10 5.895e-10 6.887e-10) set test5 = $test3 - $test4 but this doesn't seem to work. And then I tried: @ test5 = $test3 - $test4 This doesn't seem to work... (8 Replies)
Discussion started by: EDALBNUG
8 Replies

8. UNIX for Dummies Questions & Answers

Reading a file in C shell

I recently started working in c shell and I am embarrassed to say I can't get a single read using while command to work while read line do print $line done < list.txt Can somebody help. I need a solution specific to C shell. The error I get is "while: Expression Syntax." (3 Replies)
Discussion started by: paruthiveeran
3 Replies

9. Shell Programming and Scripting

add numbers in shell script

cat dailyreports | grep "Important list" | awk -F":" '{print $2}' | awk -F" " '{print $1}' hey guys, after running the above combination of cat and awk, i get the below output: 3 4 2 9 now, i need to add these numbers up all in one line. i dont know what to add to that cat and awk one... (2 Replies)
Discussion started by: Terrible
2 Replies

10. Shell Programming and Scripting

retain Line numbers.. in Vi .. OR .. A SHELL SCRIPT

Hello everybody ! GOT SOMETHING INTERESTING... I am trying to retain line number for a text document.. usually we get line numbers in VI using :set nu , but I want to permanently store them. It's a 4000 lines of text and I want grep/search it for a list of words/fields stored in a different... (2 Replies)
Discussion started by: sdlayeeq
2 Replies
Login or Register to Ask a Question