linux 如果一直 cd 进入指定目录,较为繁琐。如何自定义选择进入指定目录呢?
答:可以通过shell脚本实现。
需要用到以下命令:
在linux终端输入以下命令:
torch d.sh // 创建文件
vim d.sh // 编辑shell脚本
chmod +x d.sh // 添加执行权限
. ./d.sh # 执行shell脚本
# 不能直接 ./d.sh,这样是创建一个子shell让其执行脚本,但是不会影响父shell的环境变量,所以执行完后目录没改变
# 需要用 source(或 .)命令,直接在当前的shell环境下执行脚本 ,不会创建子shell;
待编辑的shell脚本文件 d.sh 如下:
read -p "输入:" x
echo "$x"
#jugemet $x value is none or not
if [ "$x" == "" ];then
echo "error"
exit 5
fi
if [ "$x" == "cnn" ];then # [ ] 和 == 左右一定要有空格
echo "cnn"
cd ./code/pytorch-tutorial/02-intermediate/convolutional_neural_network
pwd
elif [ "$x" == "lm" ];then
echo "lm"
cd ./code/pytorch-tutorial/02-intermediate/language_model
pwd
elif [ "$x" == "rnn" ];then
echo "rnn"
cd ./code/pytorch-tutorial/02-intermediate/recurrent_neural_network
pwd
elif [ "$x" == "bi-rnn" ];then
echo "bi-rnn"
cd ./code/pytorch-tutorial/02-intermediate/bidirectional_recurrent_neural_network
pwd
elif [ "$x" == "dsn" ];then
echo "dsn"
cd ./code/pytorch-tutorial/02-intermediate/deep_residual_network
pwd
else
echo "待添加..."
fi