How to get the first character of a string in Bash

2 Answers

0 votes
s="bash Unix shell and command language"
 
firstcharacter=${s::1}

echo $firstcharacter
 
 
 
# run:
#
# b
#

 



answered Feb 6, 2021 by avibootz
0 votes
s="bash Unix shell and command language"

firstcharacter=${s:0:1}
 
echo $firstcharacter
  
  
  
  
# run:
#
# b
#

 



answered Feb 7, 2021 by avibootz

Related questions

1 answer 331 views
2 answers 294 views
1 answer 260 views
1 answer 227 views
2 answers 286 views
1 answer 300 views
1 answer 256 views
...