一、设置PATH环境变量的方法,建议用~/.bash_profile的方法,不然在ssh登录的时候可能没有设置PATH.
二、下面的完整的脚本,里面的echo "export PATH=$build_toolchain_path:\$PATH" >> $HOME/.bashrc 就是把交叉编译路径写写到.bashrc设置PATH环境变量。
#!/bin/bash# command to install toolchain in the "dirname" which you Specified.
# source ./env_install_toolchain.sh dirname
INSTALL_TARGET_DIR=
toolchain_cross=`pwd`
toolchain_cross=$(basename ${toolchain_cross})
if [ -n "$1" ]; thenif [ -d "$1" ]; thenINSTALL_TARGET_DIR=$1build_toolchain_path="${INSTALL_TARGET_DIR}/$toolchain_cross/bin"elseecho "error: not found dir $1"echo "command format: source $0 [dirname]"echo " [dirname] is optional"return 1fi
elsebuild_toolchain_path="${PWD}/bin"
fi# default 1
selectopt=1case $selectopt in0)if [ -n "$INSTALL_TARGET_DIR" ]; thensudo cp -rfa $PWD $INSTALL_TARGET_DIRfisudo echo "export PATH=$build_toolchain_path/:\$PATH" >> /etc/profilesource /etc/profile;;1)if [ -n "$INSTALL_TARGET_DIR" ]; thencp -rfa $PWD $INSTALL_TARGET_DIRficmdsed="sed -i '/^export PATH.*${toolchain_cross}\/bin/d' \$HOME\/.bashrc"eval $cmdsedecho "export PATH=$build_toolchain_path:\$PATH" >> $HOME/.bashrcsource $HOME/.bashrccmdsed="sed -i '/^export PATH.*${toolchain_cross}\/bin/d' \$HOME\/.bash_profile"eval $cmdsedecho "export PATH=$build_toolchain_path:\$PATH" >> $HOME/.bash_profilesource $HOME/.bash_profile;;*)echo "Please check input.";;
esac
三、运行完上面的脚本之后的效果。