Counting Characters in a Bash String
📖 Scenario: You are working on a simple bash script to help count the number of characters in a word. This is useful when you want to check the length of names, passwords, or any text input in your scripts.
🎯 Goal: Build a bash script that stores a word in a variable, then calculates and shows the number of characters in that word using the ${#var} syntax.
📋 What You'll Learn
Create a variable called
word with the exact value helloCreate a variable called
length that stores the length of word using ${#word}Print the value of
length to show the number of characters in word💡 Why This Matters
🌍 Real World
Counting string length is useful in scripts that validate user input, like checking password length or formatting text.
💼 Career
Many automation and scripting jobs require handling text data and validating input lengths to ensure correct processing.
Progress0 / 4 steps