I have a Bash variable, $word
, which is sometimes a word or sentence, e.g.:
word=\"tiger\"
Or:
word=\"This is
With cut :
word='tiger'
echo "${word}" | cut -c 1
Using bash 4:
x="test"
read -N 1 var <<< "${x}"
echo "${var}"
initial="$(echo $word | head -c 1)"
Every time you say "first" in your problem description, head
is a likely solution.
word=something
first=${word::1}
A portable way to do it is to use parameter expansion (which is a POSIX feature):
$ word='tiger'
$ echo "${word%"${word#?}"}"
t
word="tiger"
firstletter=${word:0:1}