Sponsored Content
Top Forums Shell Programming and Scripting bash: testing if string is a number Post 302080581 by eur0dad on Wednesday 19th of July 2006 04:57:38 PM
Old 07-19-2006
bash: testing if string is a number

How do you test if a string is a number?

Trying to do something like this:

x="AS"
if( x is not a number ); then
x=0
fi

Because I want to do number arithmetic with x.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Testing the last character in a string

Hi In the shell scripted I'm trying to write! I would like to test the last character in a string. The string is a path/directory and I want to see if the last character is a '/'. The string (path/directory) is inputted by a user. If the '/' character isn't present then I want to be able to... (11 Replies)
Discussion started by: dbrundrett
11 Replies

2. Shell Programming and Scripting

Number/string format in bash

I would like to change the format of an integer type number adding zeros to the left of it in a script in bash. For example number=1 echo $number 00001 Thanks (3 Replies)
Discussion started by: josegr
3 Replies

3. Shell Programming and Scripting

how to format a number in bash

Say I have a number x=123, but I want to it be x=000123, because I need to use it in as a file name. thanks! (2 Replies)
Discussion started by: aerosols
2 Replies

4. Shell Programming and Scripting

changing number in bash (number is in form of string)

I have a txt file as database. when i run my program what it does is it ask me for 3 name and stored in the file as name1:name2:name3:1 when u enter 3 name it add those in file as above format and add 1 at the end. I what i want is if i enter same names again it changes that 1 to 2 and so... (3 Replies)
Discussion started by: Learnerabc
3 Replies

5. Shell Programming and Scripting

bash script for testing existence of files/folders and creating if neither exist

Hi, I am new to shell-scripting, and doing a lot of reading. I am having some trouble getting started with a simple testing of scripting. I have been experimenting with if, loops, for, test, etc., but still unsure. I seem to have the hang of it when it comes to creating a single file or... (6 Replies)
Discussion started by: me2
6 Replies

6. UNIX for Dummies Questions & Answers

Testing for non-zero length string

Hello, can someone please explain to me why this happens: myserver#echo "$nothing" myserver#if ; then echo "nothing is a zero length string"; fi nothing is a zero length string myserver#if ; then echo "nothing is also a non-zero length string, apparently"; fi nothing is also a non-zero... (5 Replies)
Discussion started by: longjon
5 Replies

7. Shell Programming and Scripting

Incrementing number in bash

I have the following code and getting the error ./raytrac.bash: line 231: ((: 0++: syntax error: operand expected (error token is "+") iarg = 0 iarg=0 narg=$# # Number of arguments passed. echo "narg = $narg" argsArr=("$@") # Set... (1 Reply)
Discussion started by: kristinu
1 Replies

8. Shell Programming and Scripting

Testing the length of a string

Hello, Unix-Forums! Is there a command that can check how long a user-entered string is? Please don't give me a code, just the name of the command (playing around yourself is much more fun than just pasting code) edit: I'm sorry, first hit of the forum search gave me the answer. (1 Reply)
Discussion started by: intelinside
1 Replies

9. UNIX for Beginners Questions & Answers

Escape bash-special character in a bash string

Hi, I am new in bash scripting. In my work, I provide support to several users and when I connect to their computers I use the same admin and password, so I am trying to create a script that will only ask me for the IP address and then connect to the computer without having me to type the user... (5 Replies)
Discussion started by: arcoa05
5 Replies

10. UNIX for Beginners Questions & Answers

Concatenate a string and number and compare that with another string in awk script

I have below code inside my awk script if ( $0 ~ /SVC IN:/ ) { svc_in=substr( $0,23 , 3); if (msg_start == 1 && msg_end == 0) { msg_arr=$0; } } else if ( $0 ~ /^SVC OUT:/ ) { svc_out=substr( $0, 9, 3); if (msg_start == 1 && msg_end == 0) ... (6 Replies)
Discussion started by: bhagya123
6 Replies
TCUTEST(1)							   Tokyo Cabinet							TCUTEST(1)

NAME
tcutest - test cases of the utility API DESCRIPTION
The command `tcutest' is a utility for facility test and performance test. This command is used in the following format. `rnum' specifies the number of iterations. `anum' specifies the initial number of elements of array. `bnum' specifies the number of buckets. tcutest xstr rnum Perform test of extensible string. tcutest list [-rd] rnum [anum] Perform test of array list. tcutest map [-rd] [-tr] [-rnd] [-dk|-dc|-dai|-dad|-dpr] rnum [bnum] Perform test of hash map. tcutest tree [-rd] [-tr] [-rnd] [-dk|-dc|-dai|-dad|-dpr] rnum Perform test of ordered tree. tcutest mdb [-rd] [-tr] [-rnd] [-dk|-dc|-dai|-dad|-dpr] rnum [bnum] Perform test of on-memory hash database. tcutest ndb [-rd] [-tr] [-rnd] [-dk|-dc|-dai|-dad|-dpr] rnum Perform test of on-memory tree database. tcutest misc rnum Perform test of miscellaneous routines. tcutest wicked rnum Perform updating operations of list and map selected at random. Options feature the following. -rd : perform the reading test also. -tr : perform the iterator test also. -rnd : select keys at random. -dk : use the function `tcxxxputkeep' instead of `tcxxxput'. -dc : use the function `tcxxxputcat' instead of `tcxxxput'. -dai : use the function `tcxxxaddint' instead of `tcxxxput'. -dad : use the function `tcxxxadddouble' instead of `tcxxxput'. -dpr : use the function `tcxxxputproc' instead of `tcxxxput'. This command returns 0 on success, another on failure. SEE ALSO
tcumttest(1), tcucodec(1), tcutil(3), tokyocabinet(3) Man Page 2011-02-12 TCUTEST(1)
All times are GMT -4. The time now is 08:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy