Код: Выделить всё
#!/bin/bash
# ---------- echoline.sh ----------
to_stderr=false
### get input
set -f # stops * being expanded
cml_args="$*" ### flags passed via pipe are caught here
### parse input
while getopts ":seco:" arg; do
case "${arg}" in
e)
cml_args=${cml_args//"-e"/}
;;
*)
;;
esac
done
### output to console
printable=$( IFS=$'\n'; echo "${cml_args[*]}" )
if [[ $to_stderr == false ]]; then
echo "$printable"
else
echo "$printable" 1>&2
fi
Код: Выделить всё
#!/bin/bash
# ---------- first.sh ----------
echoLine() {
./echoline.sh "$@"
}
get_serial_number() {
echoLine -e "This is supposed to write to stderr, but actually writes to stdout"
echo "This is supposed to write to stdout and does."
}
main() {
echoLine -e "I can write to stderr here just fine!"
example_serial=$(get_serial_number)
echo "example_serial = $example_serial"
}
main
Код: Выделить всё
[root@DESKTOP-A8HSSI8 test]# ./first.sh
I can write to stderr here just fine!
example_serial = This is supposed to write to stderr, but actually writes to stdout
This is supposed to write to stdout and does.
Подробнее здесь: https://stackoverflow.com/questions/787 ... bstitution
Мобильная версия