How to check the first two characters of a string in Bash

1 Answer

0 votes
s="bash Unix shell and command language"
 
if [[ ${s::2} == "ba" ]]
then
  echo 1;
else
  echo 0; fi
 
 
 
# run:
#
# 1
#

 



answered Feb 6, 2021 by avibootz

Related questions

1 answer 220 views
2 answers 272 views
1 answer 246 views
1 answer 252 views
2 answers 568 views
1 answer 314 views
2 answers 285 views
...