最近,我一直在尝试自定义位于~/.profile
Ubuntu中的shell配置文件。我想做的一件事是:
# PATH-like variable containing paths separated by ':'
MY_ROOTS=/f/o/o:/b/a/r:/e/t/c
for some magic iterating my_root in $MY_ROOTS do;
my_bin="$my_root/bin"
# add it to PATH!
[ -d "$my_bin" ] && {
expr ":$PATH:" : ".*:$my_bin:.*" >/dev/null || PATH="${PATH:+"$PATH:"}$my_bin"
}
done
由于它位于.profile中,因此我需要使该iterating
零件与Bourne Shell兼容。许多人都问过这样的问题,但是我相信大多数解决方案看起来都是Bashism。在花了很多时间进行谷歌搜索之后,我仍然没有找到合适的答案。请问您的意见。
尝试:
OIFS="$IFS"
IFS=:
MY_ROOTS=/f/o/o:/b/a/r:/e/t/c
for my_root in $MY_ROOTS; do
# your code here with $my_root
done
IFS="$OIFS"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句