How to obtain the first letter in a Bash variable?
Solution 1:
word="tiger"
firstletter=${word:0:1}
Solution 2:
word=something
first=${word::1}
Solution 3:
initial="$(echo $word | head -c 1)"
Every time you say "first" in your problem description, head
is a likely solution.
Solution 4:
A portable way to do it is to use parameter expansion (which is a POSIX feature):
$ word='tiger'
$ echo "${word%"${word#?}"}"
t