How to get the first N characters from a string in Bash

2 Answers

0 votes
s="bash Unix shell and command language"

N=6
s=${s::N}

echo $s



# run:
#
# bash U
# 

 



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

N=6
s=${s:0:N}

echo $s



# run:
#
# bash U
# 

 



answered Feb 5, 2021 by avibootz

Related questions

1 answer 364 views
1 answer 337 views
1 answer 317 views
1 answer 320 views
2 answers 438 views
1 answer 396 views
2 answers 738 views
...