EasyEnv
Engineering/Courses/Catalog/Bash/String and Arithmetic Expansion
Bash
BeginnerLesson 8 of 1225 min · hands-on

String and Arithmetic Expansion

Part of the Bash course

You will constantly find yourself with a variable that holds almost, but not quite, what you need. A full file path when you only want the filename. A filename when you only want the extension. A sentence where one word needs swapping out. A pair of numbers you need added together for a report.

Imagine a price tag that reads $19.99 and you want just the number, 19.99, with the dollar sign trimmed off the front. Or a photo file called vacation.jpg where you want just vacation, with the .jpg trimmed off the back. Bash has a piece of syntax for exactly this kind of trimming, and it does not need any external tool. ...

Want to learn Bash String and Arithmetic Expansion in a real environment?

Click below, get a fresh Linux box with Bash ready to go, and work through String and Arithmetic Expansion hands-on with an AI tutor that knows your code.

Start this lessonString and Arithmetic Expansion

What you'll learn

  • ${var#prefix}
  • ${var%suffix}
  • ${var//old/new}
  • $(( arith ))
  • Printf formatting

Read this lesson in your language

All lessons in this course

12 lessons
  1. 1What Is Bash20 min
  2. 2Shebang and Your First Script25 min
  3. 3Variables and Quoting25 min
  4. 4Conditionals and Tests30 min
  5. 5Loops25 min
  6. 6Functions25 min
  7. 7Arrays25 min
  8. 8String and Arithmetic Expansion25 min
  9. 9IO Redirection and Pipes25 min
  10. 10Error Handling and Traps30 min
  11. 11Debugging and Best Practices25 min
  12. 12Capstone: Server Bootstrap Script60 min

Explore other courses

String and Arithmetic Expansion - Bash (English) | Engineering Courses