我的代码:
SITE27=`python2.7 -c "import site; print site.getsitepackages()"`
errInfo27="$?"
echo $SITE27
if [ $errInfo27 -eq 0 ]; then
case ${SITE27} in
*\ * ) echo "VAR=$VAR has at least one space char";
;;
* ) echo "VAR=$VAR has no space chars" ;;
esac
fi
然后对于echo $ SITE27,我得到:
['/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/Library/Python/2.7/site-packages']
如何提取最后一条路径/Library/Python/2.7/site-packages?
非常感谢你。 LJ
答案 0 :(得分:1)
SITE27=$(python2.7 -c "import site; print site.getsitepackages()[-1]")
使用[-1]
获取列表的最后一个元素:site.getsitepackages()[-1]