Enable or disable running the location handlers through an atexit handler, Running scripts at exit–time. The enable operation registers an atexit handler that cleans up the current stack of locations.
It is suggested to always add the following code to the preamble of a script:
mbfl_atexit_enable mbfl_location_enable_cleanup_atexit
Suspend the test mode inside a location block, by executing the following code:
mbfl_option_test_save mbfl_location_handler mbfl_option_test_restore
For a discussion of its usage see Testing a script and running programs.
Do this:
mbfl_change_directory()
.
When successful return true, otherwise return false. When verbose mode is enabled: print messages describing the entering and leaving of directories.
When called, save the state of the lastpipe
option of shopt
using:
shopt -p lastpipe
Upon exiting the location: the handler restores the previous status of lastpipe
.
See The Shopt Builtin.
Using this handler is helpful when the last command of a pipe is executed in the current shell, rather than a subshell, to store the result of a computation in a shell variable.
declare RESULT mbfl_location_enter { mbfl_location_handler_restore_lastpipe shopt -s lastpipe output_something | while read do RESULT+=$REPLY done } mbfl_location_leave # use $RESULT
When called, save the state of the nullglob
option of shopt
using:
shopt -p nullglob
Upon exiting the location: the handler restores the previous status of nullglob
.
See The Shopt Builtin.
mbfl_location_enter { mbfl_location_handler_restore_nullglob shopt -s nullglob declare MATCH # The loop never executes its body if there are no files # matching the pattern. for MATCH in /path/to/*.tex do # do something done } mbfl_location_leave
This document describes version 3.0.0-devel.9 of Marcos Bash Functions Library.