#!/bin/bashfunction limitSubStringLenght {# 1ドル => main string# 2ドル => substring pattern (regex)# 3ドル => max lenghtwork="1ドル"whileIFS=read -r result
do# $result contain substring matched# save a copy of the cuted version of the substringendCut=$(echo$result| cut -c 1-"3ドル")# cut the substring in the main stringwork=$(echo -n "$work"| sed "s#$result#$endCut#g")# we set the substring to match heredone < <(echo"1ドル"| grep -Eo "2ドル")echo -n "$work"}# set the example variablediskInfos=$(echo -n '[fuser.sshfs] /media/partition/blablabla 1.2GB / 2.4GB')# displaying test example before change itecho' BEFORE => '"$diskInfos"# apply change and save it in to $diskInfosdiskInfos=$(limitSubStringLenght "$diskInfos"'(/[a-Z0-9._]{1,}){1,}/{0,}'20)# displaying resultsecho -n ' AFTER_ => '"$diskInfos"
# Solution
Posté par voxdemonix . En réponse au message [Bash] Limiter taille substring. Évalué à 1.
Ce qui produit :
Enjoy 😉