我做了以下脚本,
preamble.sh
,我从每个脚本A,B,C调用:
#!/bin/bash
# Change the color of our output
# TODO: How to redefine echo for the parent caller?
PURPLE='\033[1;35m'
NC='\033[0m' # No Color
function echo() { builtin echo -e '\033[1;35m'$0'\033[0m'; }
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) machine=Linux ;;
Darwin*) machine=Mac ;;
CYGWIN*) machine=Cygwin ;;
MINGW*) machine=MinGw ;;
*) machine="UNKNOWN:${unameOut}" ;;
esac
echo "[Running on ${machine}...]"
当我这么做的时候
bash preamble.sh
preamble.sh
紫色(我希望echo在每个脚本A、B、C等中使用的颜色)。
我想最终发生的是回声被重新定义了
前言.sh
但这并不是我所期望的。我打电话的时候
前言.sh
因为这一定是论点
$0
我意识到我可能在做一些不可能直接做的事情。
我如何实现我正在努力实现的目标?