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 314 views
2 answers 285 views
1 answer 252 views
1 answer 215 views
2 answers 272 views
1 answer 288 views
1 answer 249 views
...