In my script I ask the user for some input and save it into some variables. Before using the strings in the variables I want to cut them if they are too long and add an ellipsis at the end. So I put all of the variables in an array and send them through a loop and an if statement and reasign the new value to the variable in the array. I have tried many ways and none have worked. The following being an example:
preset1="Short string"
preset2="Not long very string"
preset3="A very long string here which we will then cut"
presets=("${preset1}" "${preset2}" "${preset3}")
for x in "${presets[@]}"; do
if [[ "${#x}" -gt 20 ]]; then
y="${x:0:20}..."
presets[$x]="$y"
fi
done
Please help!