How do I set up a bash alias for a common working folder?

JohnGB

I want to set up a bash alias or function (let's call it "myfolder") to a common working directory (let's call it ~/some/deep/working/folder) and I want to be able to call it like this:

cd myfolder/bob to access the child folder "bob".

If I use alias myfolder='~/some/deep/working/folder', I can use cd myfolder, but I can't use cd myfolder/bob.

How do I get the alias expansion to happen first, and then have any other text be added onto the command before executing the command?

Cyrus

Two workarounds:

Add this to your .bashrc:

CDPATH="$CDPATH:$HOME/some/deep/working"

then you can use

cd folder/bob

from everywhere.


Use a variable:

myfolder="$HOME/some/deep/working/folder"
cd "$myfolder/bob"

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How do I set up a server for SSH?

분류에서Dev

How do I set up an email server?

분류에서Dev

How do I set the at command shell to bash?

분류에서Dev

How do I set up live audio streams to a DLNA compliant device?

분류에서Dev

How do I set up Emacs on Linux to read/send mail from Gmail?

분류에서Dev

How do I set up an iAd that works for both iOS 5 and 6? and if possible compatible with all iOS

분류에서Dev

How do I set up a second display via DVI/viewport with a Lenovo T420S?

분류에서Dev

How do I set up Launchy's Runner plugin to launch Everything search

분류에서Dev

How do I set up a multi-project solution in C++?

분류에서Dev

How do I set up a local SOCKS proxy that tunnels traffic through SSH?

분류에서Dev

How do I set up SSH to transfer files from my local machine to a shared server with rsync?

분류에서Dev

Flycheck and Clutter - how can I set it up?

분류에서Dev

Set up git alias with an input argument

분류에서Dev

How do I create a new folder in Mutt

분류에서Dev

How do I set an executable's working directory via the command line, prior to executing it?

분류에서Dev

How do I include an ampersand in the column alias name in a Oracle query

분류에서Dev

How do I refer to an outside alias from inside a piglatin macro?

분류에서Dev

How do I speed up this for loop in r

분류에서Dev

How can I run a bash in every subfolder of a base folder

분류에서Dev

Bash CD up until in certain folder

분류에서Dev

Should I create an alias for each bash function?

분류에서Dev

how do i get "this = this" in prototype working

분류에서Dev

How do you set up unit tests without Karma?

분류에서Dev

How do I print date data with bash

분류에서Dev

How can I set up logging for node-mongod-native?

분류에서Dev

How can I set up Git branch for automatic backups

분류에서Dev

How can I set up conditional associations in Rails?

분류에서Dev

How can I set up a house-wide sound system?

분류에서Dev

How do you list the folder permissions of only certain directories that follow a common pattern in a particular directory?

Related 관련 기사

  1. 1

    How do I set up a server for SSH?

  2. 2

    How do I set up an email server?

  3. 3

    How do I set the at command shell to bash?

  4. 4

    How do I set up live audio streams to a DLNA compliant device?

  5. 5

    How do I set up Emacs on Linux to read/send mail from Gmail?

  6. 6

    How do I set up an iAd that works for both iOS 5 and 6? and if possible compatible with all iOS

  7. 7

    How do I set up a second display via DVI/viewport with a Lenovo T420S?

  8. 8

    How do I set up Launchy's Runner plugin to launch Everything search

  9. 9

    How do I set up a multi-project solution in C++?

  10. 10

    How do I set up a local SOCKS proxy that tunnels traffic through SSH?

  11. 11

    How do I set up SSH to transfer files from my local machine to a shared server with rsync?

  12. 12

    Flycheck and Clutter - how can I set it up?

  13. 13

    Set up git alias with an input argument

  14. 14

    How do I create a new folder in Mutt

  15. 15

    How do I set an executable's working directory via the command line, prior to executing it?

  16. 16

    How do I include an ampersand in the column alias name in a Oracle query

  17. 17

    How do I refer to an outside alias from inside a piglatin macro?

  18. 18

    How do I speed up this for loop in r

  19. 19

    How can I run a bash in every subfolder of a base folder

  20. 20

    Bash CD up until in certain folder

  21. 21

    Should I create an alias for each bash function?

  22. 22

    how do i get "this = this" in prototype working

  23. 23

    How do you set up unit tests without Karma?

  24. 24

    How do I print date data with bash

  25. 25

    How can I set up logging for node-mongod-native?

  26. 26

    How can I set up Git branch for automatic backups

  27. 27

    How can I set up conditional associations in Rails?

  28. 28

    How can I set up a house-wide sound system?

  29. 29

    How do you list the folder permissions of only certain directories that follow a common pattern in a particular directory?

뜨겁다태그

보관