@
ynyounuo v 友 请教如何在 zsh 下把 mac 自带的 BSD 命令替换成 gnu 命令? 以下是我用的步骤无法生效 , 能帮忙看下哪里改错了吗? 万分感谢
我是 zsh 下执行以下脚本 , 用 bash
xxx.sh #!/usr/bin/env bash
print_usage() {
cat <<- EOF
use gnu tools without prefix "g" on mac, for example, "cat" rather than "gcat"
EOF
exit 0
}
if [[ $1 =~ -h|--help ]]; then
print_usage
fi
gnu_bin_path=/usr/local/gnubin
if [[ ! -d $gnu_bin_path ]]; then
mkdir $gnu_bin_path
fi
for i in /usr/local/opt/*/libexec/gnubin/*
do
ln -s $i $gnu_bin_path
done
echo "finish"
然后增加 PATH=/usr/local/gnubin/:$PATH
export PATH
到.zprofile
添加这段脚本在~/.zprofile 中:
join_str() {
sep="$1"
shift
first_word="$1"
shift
printf "%s" "$first_word" "${@/#/$sep}"
}
manpath=(/usr/local/opt/**/libexec/gnuman/)
joined_manpath=`join_str : ${manpath[@]}`
MANPATH=$joined_manpath:$MANPATH
export MANPATH
unset manpath
unset joined_manpath
@
ynyounuo @
jorneyr