Skip to main content

Questions tagged [arithmetic]

This tag is meant for everything that has to do with mathematical operations. So if you want to ask a question about doing calculations in `awk`, or if you have a question about `bc`, this is the right tag to use.

12 votes
2 answers
1k views

I was debugging one script, and discovered unexpected behavour of handling arithmetic syntax error. Normally, when error happens, script is just continuing execution. #!/bin/bash func2 () { echo &...
Ashark's user avatar
  • 1,219
4 votes
1 answer
303 views

I am using the bc calculator with obase and ibase to convert integer representation. I'm not used to it, because very basic things can be done with $(( expresion )) in bash, and most things that can't ...
Gyro Gearloose's user avatar
2 votes
1 answer
495 views

Bash accepts both these syntax: FOO=$(($BAR + 42)) and FOO=$((BAR + 42)) Which one is correct / most portable / less prone to errors? Or are both equally valid?
dr_'s user avatar
  • 32.4k
-3 votes
1 answer
211 views

Hypothetic example: There is a number that I will split into x parts (smaller numbers, in a range you see in the example). I need a way, ideally a one liner for the Linux Bash, to split a large number ...
user447274's user avatar
1 vote
5 answers
281 views

Scenario I have containers which have last deploy dates in the format: month/date/year or feb/11/2024. I cant change the way they output the last deploy date. I'd like to subtract the last deploy date,...
Nickotine's user avatar
  • 554
-1 votes
2 answers
173 views

I'm trying to write a command that looks at my battery state and suspends the laptop if the battery is low. I tried using something like this: #!/bin/bash if [ $(acpi -b | cut -c 25) < 11 ] then ...
Alexander Praehauser's user avatar
0 votes
1 answer
68 views

In relation to this: https://unix.stackexchange.com/a/754252/582781 Solution 1: free -g -s2 | sed -u -n 's/^Mem:\s\+[0-9]\+\s\+\([0-9]\+\)\s.\+/\1/p' >> memory.log Is there a way to add Swap to ...
Aleksander's user avatar
-4 votes
1 answer
133 views

Variables can be protected with curly braces. Mynewvar=1 echo $Mynewvar 1 echo ${Mynewvar} 1 However I can no longer protect them when inside shell arithmetic. Mynewvar=1 echo $((Mynewvar+9)) 10 echo ...
jwav629's user avatar
3 votes
4 answers
615 views

So far I have this: sudo find /path/to/dir -type f | xargs -d "\n" sudo stat -c "%Y %n" | {arithmetic to check if %Y is between 1685518962 and 1685624474??} | {show ...
MonkeyZeus's user avatar
1 vote
1 answer
352 views

From a bash script I am downloading a file from a server using curl call. Now I want to check if the file is fully downloaded. For this I am comparing the size of downloaded file and Content-Length ...
Preeti 's user avatar
  • 223
-5 votes
1 answer
357 views

hi i am new to programming and currnetly learing bash script. please help with this error " line 28: expected `)' " Given below is my program. read -p "enter the number:" a while [...
KNIGHTSS's user avatar
-1 votes
1 answer
2k views

I just want someone to explain what an "operand" is because I just don't understand it. Here is the context I'm reading this in: In the section about Shell Arithmetic in the bash shell ...
john smith's user avatar
9 votes
1 answer
11k views

I think the line below should be written differently, and the command should bug out. $ echo $((x=2, y=3, x+y)) 5 I thought the way to write this was: $ echo $((x=2, y=3, $x+$y)) 5 Both work, which ...
john smith's user avatar
2 votes
1 answer
159 views

I want to print the lines of updates via this command dnf check-update --refresh --q --downloadonly | wc -l However during the output there occurs a blank line which means the true update number is ...
camarman's user avatar
  • 153
0 votes
2 answers
108 views

I want to get my data usage from my wifi device to display on my top bar, I can get the data usage in bytes using curl like this $bytes=(curl -d "Page=GetWANInfo" -X POST http://jiofi.local....
adumbProgrammer's user avatar

15 30 50 per page
1
2 3 4 5
14