How to retrieve the first n characters of a variable in Bash? [duplicate]

If the variable is: FOO="qwertzuiopasdfghjklyxcvbnm"

then

 echo ${FOO:0:10}

will give the first 10 characters.


Use the head command.

echo $FOO | head -c 10
=> qwertzuiop