Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read string from file and convert into an int [closed]

Tags:

string

bash

int

I have a txt file with ONLY a number inside; it can be any number, how can i read it from bash and convert it into an int?

As i said, the only thing in the file is the number, no other thing, but when reading it, bash gets it as a string.

Thanks in advance!

like image 851
Ghost Avatar asked Jul 15 '13 15:07

Ghost


1 Answers

Use declare or typeset:

typeset -i variable=$(cat filename)
like image 53
Barmar Avatar answered Oct 03 '22 22:10

Barmar