Saturday, February 7, 2009

substring operation with bash

You can get a substring (substr) value of an string variable as following in bash.
Syntax is simple ${VARIABLE_NAME:start:length}

let's assume we have a string variable called mystring and it has the value "test".


If you want to access first character of the string you can use following statement.

now c value contains "t" character.


Now c contains "st" substring.

Hint: You can calculate the length of a string value as follows.


No comments: