Join Scott Simpson for an in-depth discussion in this video Working with numbers, part of Learning Bash Scripting.
…Working with numbers in Bash is pretty straight forward.…To tell the interpreter that you're going to do math,…you need to wrap an expression up in double parenthesis.…If you're assigning the result of an arithmetic expression to…a variable, the paren's need to start with a dollar sign.…The expression inside the parenthesis can use either literal numbers or variables.…Batch supports six basic arithmetic operators.…Exponentiation with double asterisks, multiplication with a single asterisk,…division with a forward slash, modulo with a percent sign.…Addition with a plus, and subtraction with a minus.…
I'll define a variable d to equal two.…And then I'll define e to equal the result of d plus two.…Then I'll echo out the value of e.…And I'll save.…And then I'll run my script.…And I see four, two plus two.…We…can also use the increment and decrement operators that you might be familiar with.…And the combination assignments.…e plus equals five would increment the value of e by five.…e times equal three, e divided by equals three, and e minus equals five.…
- What is Bash?
- Managing output with grep, awk, and cut
- Understanding Bash script syntax
- Creating a basic Bash script
- Displaying text with "echo"
- Working with numbers, strings, and arrays
- Reading and writing text files
- Working with loops
- Using functions
- Getting user input during execution
- Ensuring a response
Skill Level Beginner
1. Working with the Command Line
2. Building Bash Scripts
3. Control Structures
4. Interacting with the User
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.