i'm trying build long command involving find
. have array of directories want ignore, , want format directory command.
basically, want transform array:
declare -a ignore=(archive crl cfg)
into this:
-o -path "$dir/archive" -prune -o -path "$dir/crl" -prune -o -path "$dir/cfg" -prune
this way, can add directories array, , find
command adjust accordingly.
so far, figured out how prepend or append using
${ignore[@]/#/-o -path \"\$dir/} ${ignore[@]/%/\" -prune}
but don't know how combine these , simultaneously prepend , append each element of array.
you cannot simultaneously. fortunately, not need to:
ignore=( archive crl cfg ) ignore=( "${ignore[@]/%/\" -prune}" ) ignore=( "${ignore[@]/#/-o -path \"\$dir/}" ) echo ${ignore[@]}
note parentheses , double quotes - make sure array contains 3 elements after each substitution, if there spaces involved.
Comments
Post a Comment