select first character string bash 1

select first character string bash

foo="bar"
echo ${foo:0:1}  
#{str:position:length}
#returns f

Here is what the above code is Doing:
1. The first echo statement prints the value of the variable foo.
2. The second echo statement prints the first character of the variable foo.
3. The third echo statement prints the first two characters of the variable foo.
4. The fourth echo statement prints the first character of the variable foo.

Similar Posts