2023年3月31日 星期五

[bash] parameter substitution

get string after c

${target#*c}        # first match

${target##*c}      # last match

get string before c

${target%.*}        # last match

${target%%.*}     # first match

separated to list by c

lst=(${target//c/ })

get list elements

lst=0 1 2 3 4 5 6 7

${lst[@]:5:2} # form 5th element take 2 elements

got 5 6

沒有留言:

張貼留言