Tag Info

New answers tagged

1

From man bash: set -u Treat unset variables and parameters other than the special parameters "@" and "*" as an error when performing parameter expansion. If expansion is attempted on an unset variable or parameter, the shell prints an error message, and, if not -interactive, exits with a nonzero status. POSIX states that, in the event of an expansion ...


1

(I'm using bash 4.2.53). For part 1, the bash man page just says "An error message will be written to the standard error, and a non-interactive shell will exit". It doesn't say an ERR trap will be called, though I agree it would be useful if it did. To be pragmatic, if what you really want is to cope more cleanly with undefined variables, a possible ...


2

Assuming the positional parameters don't contain newline characters: [ "$#" -gt 0 ] && printf '%s\n' "$@" | #print in order sed '3,4 d' | #skip 3 and 4 tac #reverse (try tail -r on #non-GNU systems). Test: set 1 2 3 4 5 6 printf '%s\n' "$@" | sed ...


-1

With basically any shell: printf '{ PS4=\${$(($#-$x))}; } 2>&3; 2>&1\n%.0s' | x=LINENO+1 sh -sx "$@" 3>/dev/null And you don't need to use subshells. For example: set -x a b c { last= PS4=\${last:=\${$#}}; set +x; } 2>/dev/null echo "$last" ...prints... c And here is a shell function which can set a shell alias for you that will ...


0

With zsh: $ set a 'foo bar' c '' '*' $ printf '<%s>\n' "${(Oa)@}" <*> <> <c> <foo bar> <a> Oa is a parameter expansion flag to sort the array elements upon expansion in reverse array indices. To exclude 3 and 4: $ printf '<%s>\n' "${(Oa)@[5,-1]}" "${(Oa)@[1,2]}" <*> <foo bar> <a>


-3

declare -a argv=( "$@" ) for (( i=$((${#argv[@]}-1)) ; i>=0 ; i=$(($i-1)) )) ; do echo "${argv[$i]}" # use "${argv[$i]}" in here... done


0

Since inputName is a variable you can not use repexp constants /.../ (like in f && /<details input="inputName"/). Instead use dynamic regexps through strings: f && $0 ~ "<details input=" inputName where you concatenate the string "..." with variable inputName. (Note: Since you are processing XML, keep in mind, when processing XML ...


1

I am not sure awk will replace a variable by it's value in f && /<details input="inputName"/ you might wish to replace by f && /<details input="/ && index($2,inputName) > 0 edit: final awk part should be: /<machine.*name=/ { f=1 ; m=0 ; res="" } f { res = res $0 ORS } f && /<details ...



Top 50 recent answers are included