# LECA Bash library # # The LECA bash library provides a set of function used for helping # development of bash script mainly to write job script on the luke # cluster # # The files from the LECA Bash library must be sourced from your main script # # # Manages the clobber/noclobber property of the bash shell # ======================================================== # # When the noclobber mode is on you cannot substitute an existing file by a # empty one using a unix redirection. # # Functions provided: # # - setnoclobber # Sets the noclobber mode on. # You cannot erase an existing file by a redirection # # - setclobber # Sets the noclobber mode off. # You can erase an existing file by a redirection # # - getnoclobber # Returns the noclobber status as a string # - on: the noclobber mode is on # - off: the noclobber mode is off # # - pushclobber # Saves the current noclobber mode on a stack and sets it to 'off' # # - pushnoclobber # Saves the current noclobber mode on a stack and sets it to 'on' # # - popclobber # Restores the last pushed noclobber mode # # - popnoclobber # Alias for the popclobber function # include logging logdebug "Load clobber package" include stacks newstack __LECABASHLIB_CLOBBERSTACK__ function setnoclobber() { set -o noclobber } function setclobber() { set +o noclobber } function getnoclobber() { set -o | awk '($1 ~ /noclobber/) {print $2}' } function pushclobber() { pushvalue __LECABASHLIB_CLOBBERSTACK__ $(getnoclobber) setclobber } function pushnoclobber() { pushvalue __LECABASHLIB_CLOBBERSTACK__ $(getnoclobber) setnoclobber } function popclobber() { local state=0 popvalue __LECABASHLIB_CLOBBERSTACK__ state if [[ "$?" == "0" ]]; then if [[ "${state}" == "on" ]]; then setnoclobber else setclobber fi else return 1 fi return 0 } function popnoclobber() { popclobber return $? }