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 463 views
2 answers 435 views
1 answer 365 views
1 answer 345 views
2 answers 405 views
1 answer 395 views
1 answer 354 views
...