当前位置:网站首页>shell 上移目录

shell 上移目录

2022-06-09 01:18:00 ghostwritten

shell 上移目录

  • up.sh
#!/bin/bash

LEVEL=$1
for ((i = 0; i < LEVEL; i++)); do
	echo $i
	CDIR=../$CDIR
done
cd $CDIR
echo "You are in: "$PWD
sh=$(which $SHELL)
exec $sh

执行:

[email protected]:~/shell/shell-docs/scripts# pwd
/root/shell/shell-docs/scripts
[email protected]:~/shell/shell-docs/scripts# bash up.sh 
You are in: /root
[email protected]:~#

[email protected]:~/shell/shell-docs/scripts# bash up.sh 1
0
You are in: /root/shell/shell-docs

[email protected]:~/shell/shell-docs/scripts# bash up.sh 2
0
1
You are in: /root/shell
原网站

版权声明
本文为[ghostwritten]所创,转载请带上原文链接,感谢
https://ghostwritten.blog.csdn.net/article/details/125163794