How to retrieve the first n characters of a variable in Bash?
BashBash Problem Overview
How to retrieve the first 10 characters of a variable with Bash?
FOO="qwertzuiopasdfghjklyxcvbnm"
I need to get qwertzuiop
.
Bash Solutions
Solution 1 - Bash
If the variable is: FOO="qwertzuiopasdfghjklyxcvbnm"
then
echo ${FOO:0:10}
will give the first 10 characters.
Solution 2 - Bash
Use the head
command.
echo $FOO | head -c 10
=> qwertzuiop