Reading a line from a file and converting to int

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

As I said, the only thing in the file is the number, nothing else, but reading it, bash gets it as a string.

Thanks in advance!

+4
source share
1 answer

Use declare or typeset :

 typeset -i variable=$(cat filename) 
+8
source

Source: https://habr.com/ru/post/1491471/


All Articles