recentpopularlog in

Copy this bookmark:





to read

bookmark detail

bash - How can I prevent unsupported 'shopt' options from causing errors in my .bashrc? - Unix & Linux Stack Exchange | https://unix.stackexchange.com/
But if you really dislike redirecting the error away, you can use the completion mechanism to perform introspection. This assumes that you don't have antiquated machines with bash ≤ 2.03 that didn't have programmable completion.
<code class="language-bash">
shopt_exists () {
compgen -A shopt -X \!"$1" "$1" >/dev/null
}
if shopt_exists direxpand; then
shopt -s direxpand
fi
</code>

This method avoids forking, which is slow on some environments such as Cygwin. So does the straightforward 2>/dev/null, I don't think you can beat that on performance.
bash  configfile  shellscripting  shopt  programmablecompletion  tabcompletion  schooling  solution 
february 2019 by kme
view in context