Oddbean new post about | logout
 Bash - trim leading/trailing whitespace without having to resort to a tr/sed/awk/etc. pipe, using the "extglob" feature:

    # turn it on
    shopt -s extglob
    output="    This is a test    "

    # trim leading whitespaces
    output="${output##*( )}"

    # trim trailing whitespaces
    output="${output%%*( )}"
    echo "=${output}="

    # turn it off
    shopt -u extglob

#bash #linux #opensource