Skip to content

Instantly share code, notes, and snippets.

@shui
Created March 21, 2018 01:28
Show Gist options
  • Save shui/987ba6b3961fc3de6b0c41101385b381 to your computer and use it in GitHub Desktop.
Save shui/987ba6b3961fc3de6b0c41101385b381 to your computer and use it in GitHub Desktop.
Shell改变当前目录

方法一

脚本cdDes.sh

#!/bin/bash
cd /des

因为直接执行脚本是在当前shell进程的子进程中执行,所以并不能改变目录。执行的时候使用source在当前进程执行:

source cdDes.sh

. cdDes.sh

这两个是一样的。将脚本放入$PATH下更方便。

方法二

.bashrc下加入:

alias cdDes='cd /des'

然后使得.bashrc生效。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment