linux - Pass a full bash script line to another bash function to execute -


in bash code below, variable echo_all global , set either 'yes' or 'no' based on input parsing of options.

--- begin of ~/scripts/util/util-optout.sh ---

######################################## # @param    $@ # @return   return value $@ # @brief    wrapper function allow #           optional output of #           command w/wo args ####################################### optout() {     if [ ${echo_all} = 'no' ];         "$@" 1>/dev/null 2>&1         return $?     else         "$@"         return $?     fi } 

--- end of file ---

in bash file source above util-optout.sh file , use optout() function allow conditional output.. allow conditional redirection of commands output /dev/null make scripts silent.

for example in other build script have

source ~/scripts/util/util-optout.sh  optout pushd ${zlib_dir} optout rm -vf config.cache  optout cc=${build_tool_cc} ./configure ${zlib_configure_opt} --prefix=${curr_dir}/${install_dir} #      ^^^^^^^^^^^^^^^^^^^ #      ^ breaks optout() command # optout() fails when there prefixed bash env vars set cc=${...} before ./configure   optout popd optout make -c ${zlib_dir} ${zlib_compiler_opt} optout make -c ${zlib_dir} install 

for simple commands type of parameters after 'pushd' or 'rm'.. optout() works great. optout make -c ones work fine.

but gives me error commands have prefix env-vars set optout cc=${...} ./configure ...

utils/util-optout.sh: line 33: cc=gcc: command not found

is there way make optout() function work possible valid bash script line.

i know has use of "$@" or "$*" in optout() function, have studied bash man pages in detail , can't make work possible bash line cases.

so far way past limitation optout() following 3-line style; annoying.

export cc=${build_tool_cc} optout ./configure ${zlib_configure_opt} --prefix=${curr_dir}/${install_dir} unset cc 

any ideas on how reduce down single optout ... line

optout command other, , must preceded local modifications environment. command optout runs inherit environment.

cc=${build_tool_cc} optout ./configure ${zlib_configure_opt} --prefix=${curr_dir}/${install_dir} 

by way, 1 of problems encounter optout function. cannot run arbitrary command lines in fashion, simple command followed 0 or more arguments (and expect there exceptions restricted set, well).


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -