I want to write some code to allow me switching to some directories that I usually go to. Say this program is mycd
, and /a/very/long/path/name
is the directory that I want to go to.
So I can simply type mycd 2
instead of cd /a/very/long/path/name
. Here I assume mycd
knows 2
refers to that /a/very/long/path/name
. There might also be mycd 1
, mycd 3
, ... etc.
The problem is I have to write mycd
as a shell script and type . mycd 2
to do the desired thing because otherwise the script just get executed in a child script which doesn't change anything about the parent shell that I actually care about.
My question is:
can I do it without using
source
? because. mycd
assumesmycd
has to be a shell script and this might also introduce some functions that I don't want.can I implement it in some other programming languages?