: fun(){     local settings="$(shopt -p extglob)" #save extglob settings     shopt -s extglob #set extglob     read -r "$0"     declare -n var="$0" #use a nameref -- see `help declare`     var=${var##+([ \'])}; var=${var%%+([ \'])}     eval "$settings" #restore extglob settings } fun testingvar <<<"/path/file"; echo "$testingvar" fun testingvar <<<"'/path/file'"; echo "$testingvar" fun testingvar <<<"  /pa'th/ f'ile'"; echo "$testingvar"