In Bash, you can extract a substring from a string using parameter expansion. Here’s the syntax:
${string:start_position:length}
string is the variable containing the string.
start_position is the index where the substring begins (0-based).
length is the number of characters to extract (optional).
Example:
string=”Hello, World!”
substring=${string:7:5}
echo $substring # Outputs “World”
In this example, the substring starts from position 7 and is 5 characters long. If you omit the length, the substring will extend from the start position to the end of the string.