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 228 views
2 answers 285 views
1 answer 259 views
1 answer 259 views
2 answers 578 views
1 answer 331 views
2 answers 294 views
...