Skip to content
Justice Tech School

String Operations

Bash offers substring ${s:start:len}, length ${#s}, case change ${s^^} and ${s,,}, and pattern tests with [[ ]] and =~ for regular expressions.

Example
s="Hello, Bash"
echo "${s:7}" "${s:0:5}" "${#s}"
echo "${s^^}" "${s,,}"
if [[ $s =~ ^Hello ]]; then echo "starts with Hello"; fi
[[ $s == *Bash ]] && echo "ends with Bash"

Result

Bash Hello 11
HELLO, BASH hello, bash
starts with Hello
ends with Bash

Exercise

Uppercase a variable.

echo "${s}"

Quiz Test

Which gives the string length?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.