Convert number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert number
# 1  
Old 12-22-2015
Convert number

friends

as I can convert this value to number
in this example it is well but can vary the value does not help me cut from a nesecito espefifica opsiocn get zero


Code:
CantCabe     = 00023
Cant            = 23
CantPntCabe = 0000000000000034
CantPnt        = 34

if [ $CantCabe == $Cant ] && [ $CantPntCabe == $CantPnt ]; then
     echo "Archivo: OK "
  else
     echo "Archivo: NOK"
fi

# 2  
Old 12-22-2015
Not sure I understand. Please write in plain English!

Don't allow any spaces around the = sign when assigning variable. And, use -eq in lieu of == when comparing integer numbers.
Code:
if [ $CantCabe -eq $Cant ] && [ $CantPntCabe -eq $CantPnt ]; then echo "Archivo: OK ";   else echo "Archivo: NOK"; fi
Archivo: OK

This User Gave Thanks to RudiC For This Post:
# 3  
Old 12-22-2015
perfect!!!!

thank you!!!
# 4  
Old 12-22-2015
One comment.
The bash builtin arithmetics treat a number with leading zero(s) as octal.
Example:
Code:
CantCabe=0023
echo $(( $CantCabe + 1 ))
echo $(( CantCabe + 1 ))

The workaround is
Code:
echo $(( 10#$CantCabe + 1 ))

The [[ ]] compound needs the same workaround
Code:
CantCabe=0023
if [[ 10#$CantCabe -gt 22 ]]; then echo true; fi

In contrast, the [ ] test must NOT get the workaround.
This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert floating point to a number

Hello Guys, I have a floating point number 1.14475E+15 I want to convert this number in to full number (Integer or Big integer). I tried couple of functions it did not work. When I use INT=${FLOAT/.*} I am getting value as 1. I don't want a truncated value #!/bin/bash #... (9 Replies)
Discussion started by: skatpally
9 Replies

2. Shell Programming and Scripting

Convert a String to a Number

I read in two numbers from a user but the number is a string. #!/bin/bash read -p "Enter first number: " num1 read -p "Enter second number: " num2 I know you can use the the "expr" or "bc" command to automatically convert the string to a number then add them together. But I don't want to add... (10 Replies)
Discussion started by: Loc
10 Replies

3. Shell Programming and Scripting

Convert string number to a integer

I have data as below "ROWS merge process complete. thousand rows changed" I need to get a variable assigned the value of 1000. I mean convert the string thousand to 1000. Any help or pointer. Please use CODE tags as required by forum rules! (6 Replies)
Discussion started by: dsravanam
6 Replies

4. Shell Programming and Scripting

Convert UNIX rights in a number in a sh script

Hello, i'm trying to write a script sh to convert the rights of a folder or file in a number. Explain: ls -l = rwxrwxrwx so i must display 777. Do you known where i can find so convert script Thanks Use code tags, thanks. (11 Replies)
Discussion started by: steiner
11 Replies

5. Shell Programming and Scripting

How to convert number to english?

Hi gurus, I have a weird requirement. I need to convert the number to english lecture. I have 1.2 ....19 numbers I need to convert to first second third fourth, fifth, sixth... Is there any way convert it using unix command? thanks in advance. (8 Replies)
Discussion started by: ken6503
8 Replies

6. Shell Programming and Scripting

How to convert multiple number ranges into sequence?

Looking for a simple way to convert ranges to a numerical sequence that would assign the original value of the range to the individual numbers that are on the range. Thank you given data 13196-13199 0 13200 4 13201 10 13202-13207 3 13208-13210 7 desired... (3 Replies)
Discussion started by: jcue25
3 Replies

7. Shell Programming and Scripting

Convert e+ to number

Hi, I am using awk to get particular dates in seconds and the output am getting is like 1.28071e+09. How can I convert it to number format. Can anyone help me out? Thanks in advance..! (7 Replies)
Discussion started by: Kattoor
7 Replies

8. Shell Programming and Scripting

need script to convert number in hexadecimal

hi , i need a script to convert number into hexadecimal base for example: 237=>ED it s very important for me thank you in advance for you help (5 Replies)
Discussion started by: mips
5 Replies

9. Shell Programming and Scripting

Convert ip address to ip number

I want to make a script to read a list of ip addresses from a file then convert those ip addresses to ip number. ip number is made by removing the dots then transfer to a number , so the ip number transfered to binary then to decimal which will represents the ip number 0 : 4294967295 Also I... (17 Replies)
Discussion started by: moutaz1983
17 Replies

10. Shell Programming and Scripting

C Shell Script to convert a number into minutes

Could anyone tell me how to write a C shell script according to the following requirement. Write a C shell script convertmin which will read in a number, thought of as representing minutes, and print out the number of hours/minutes it represents so: Note: you are required to check exception... (1 Reply)
Discussion started by: Ringo
1 Replies
Login or Register to Ask a Question