Linux numeric calculation, linux numeric
Recommended method 3. more intuitive
In linux shell language, some variables store numbers, but when involved in numerical calculation, the error is reported. Why?
A terrible idea ...... Let's sigh.
Is there any character in 98 that is not a number?
You guessed it.
The crux of the problem has been found,
Free = 'top-n 1 | grep "Cpu (s):" | awk-F', ''{print $4} '| awk-F' [.] ''{print $1 }''
Run echo $ free> test, and then run vim test. There is a space in front of the number, and several invisible control characters in front of the space.
Here I am
[[M ^ [(B ^ [[39; 49m ^ [[m ^ [(B 97, then go through a space and change it
[[M ^ [(B ^ [39; 49m ^ [m ^ [(B97.
Hahaha,
I have been busy for a long time. Suddenly, as soon as I want to output $ free to a file, I can see other characters in wood.
Recommended Modification Scheme:
# Use the following method to delete all spaces
[Root @ localhost ~] # Free = 'echo-n $ free | sed's // g '';
Change to free = 'echo-n $ free | awk '{print $2 }''
Filter spaces. Instead, extract numbers directly ~
I was also a newbie. I wanted to use regular expressions to get numbers ...... I found this works ......
No score ...... Give the best answer ......
It turns out that there are points ......
Q: How do I perform numerical operations in linux? For example, if I want to assign $ sum to the values of tab1 [$ I] and tab [$2 ],
You are a programming language and have nothing to do with the operating system. Download a compiler corresponding to your programming language.