Quote:
Originally Posted by
ramky79
# Save, disable, and restore the verbose flag - any
# verbose output would look like errors.
typeset verbose="$(set -o |sed -n 's/^verbose *//p')"
set +v
This one even has a comment to explain what it does. It disables verbose debugging (disables
set -v if set), remembering the previous state of the flag in the
verbose variable.
Quote:
# Strip the "Connecting to host..." line, prompts, blank lines
# and login banners. What's left should only be error messages.
typeset errs="$(echo "$msgs" |
sed -e '/^Connecting to .*\.\.\.$/d' \
-e 's/sftp > //g' \
-e '/^[ ]*$/d' \
-e '/^#/d' \
-e '/^[-dDlbcps][-rwxsStTlL]\{9\}+\{0,1\} /d')"
Again, the comments are probably better than any detailed attempt at going through the individual regular expressions. Any "Connecting to ..." line is removed. Any sftp> prompt is removed. Any empty line is removed. Any line beginning with a hash sign is removed. The last one looks vaguely like it's intended to remove directory listing output.
Quote:
echo "$msgs" |
while read line
do
case "$line" in -*\ $wild)
echo ${line##* }
;;esac
done
This prints any line from
$msgs which matches a dash, followed by anything, followed by a space, followed by the value of the variable
$wild, with everything up to the last space trimmed away. (None of this involves any regular expressions, strictly speaking; both the
case statement and the
${var##subst} interpolation work with glob patterns.)
$wild is defined up at the beginning of the function as either positional argument
$3 or (if that is empty) an asterisk, which matches anything in glob wildcard notation.