The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

If you can read me, I'm broken!

Views: 12,599β€…    Votes:  2β€…
Tag : bash  
Link: πŸ” See Original Answer on Ask Ubuntu ⧉ πŸ”—

Title: Adding 1 to a variable doesn't work as expected (Bash arithmetic)
ID: /2016/09/11/Adding-1-to-a-variable-doesn_t-work-as-expected-_Bash-arithmetic_
Created: September 11, 2016
Upload: December 3, 2023    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false

An alternate method may be to keep your variables as integers and convert them to a string at the end:

echo $B
C=$( printf '%04d' $B )
echo $C

This style of working with integers in math and converting to string for the answer is more intuitive to me as I’m used to BASIC programming. I appreciate Bash doesn’t have variable typing like C and BASIC but pretending it does makes me happy.

⇧ HTML5 Videos flickering Editing OS names in /etc/default/grub - where is the OS name read from?  β‡©