Use alias and carry it on
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
Let's say I have this alias in my .bashrc
alias somedir="cd /var/www/site"
how can I use somedir
in say ... a cd
command?
e.g.
cd somedir/app/
doing this currently returns:
-bash: cd: somedir/app: No such file or directory
Is it even possible to use an alias this way?
alias bashrc
add a comment |Â
up vote
2
down vote
favorite
Let's say I have this alias in my .bashrc
alias somedir="cd /var/www/site"
how can I use somedir
in say ... a cd
command?
e.g.
cd somedir/app/
doing this currently returns:
-bash: cd: somedir/app: No such file or directory
Is it even possible to use an alias this way?
alias bashrc
3
Even if aliases were expanded in operand positions this wouldn't do what you want, you'd end up withcd cd /var/www/site/app
(note the doublecd
). Why not just use a variable?
– Fox
4 hours ago
1
export SOMEDIR="/var/www/site"; cd "$SOMEDIR/app"
– RoVo
4 hours ago
@Fox ah of course, can't believe I missed that ... could I add it to the alias, e.g.somedir/app
? (tried: answer no xD)
– ThisGuyHasTwoThumbs
4 hours ago
@RoVo I suppose that makes sense, create it as a var and then can use within the cd - ty :)
– ThisGuyHasTwoThumbs
4 hours ago
Also look up cdable vars and autocd in the bash manual (not sure if they can be combined, but one of them maybe useful)
– muru
3 hours ago
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Let's say I have this alias in my .bashrc
alias somedir="cd /var/www/site"
how can I use somedir
in say ... a cd
command?
e.g.
cd somedir/app/
doing this currently returns:
-bash: cd: somedir/app: No such file or directory
Is it even possible to use an alias this way?
alias bashrc
Let's say I have this alias in my .bashrc
alias somedir="cd /var/www/site"
how can I use somedir
in say ... a cd
command?
e.g.
cd somedir/app/
doing this currently returns:
-bash: cd: somedir/app: No such file or directory
Is it even possible to use an alias this way?
alias bashrc
alias bashrc
asked 4 hours ago


ThisGuyHasTwoThumbs
219111
219111
3
Even if aliases were expanded in operand positions this wouldn't do what you want, you'd end up withcd cd /var/www/site/app
(note the doublecd
). Why not just use a variable?
– Fox
4 hours ago
1
export SOMEDIR="/var/www/site"; cd "$SOMEDIR/app"
– RoVo
4 hours ago
@Fox ah of course, can't believe I missed that ... could I add it to the alias, e.g.somedir/app
? (tried: answer no xD)
– ThisGuyHasTwoThumbs
4 hours ago
@RoVo I suppose that makes sense, create it as a var and then can use within the cd - ty :)
– ThisGuyHasTwoThumbs
4 hours ago
Also look up cdable vars and autocd in the bash manual (not sure if they can be combined, but one of them maybe useful)
– muru
3 hours ago
add a comment |Â
3
Even if aliases were expanded in operand positions this wouldn't do what you want, you'd end up withcd cd /var/www/site/app
(note the doublecd
). Why not just use a variable?
– Fox
4 hours ago
1
export SOMEDIR="/var/www/site"; cd "$SOMEDIR/app"
– RoVo
4 hours ago
@Fox ah of course, can't believe I missed that ... could I add it to the alias, e.g.somedir/app
? (tried: answer no xD)
– ThisGuyHasTwoThumbs
4 hours ago
@RoVo I suppose that makes sense, create it as a var and then can use within the cd - ty :)
– ThisGuyHasTwoThumbs
4 hours ago
Also look up cdable vars and autocd in the bash manual (not sure if they can be combined, but one of them maybe useful)
– muru
3 hours ago
3
3
Even if aliases were expanded in operand positions this wouldn't do what you want, you'd end up with
cd cd /var/www/site/app
(note the double cd
). Why not just use a variable?– Fox
4 hours ago
Even if aliases were expanded in operand positions this wouldn't do what you want, you'd end up with
cd cd /var/www/site/app
(note the double cd
). Why not just use a variable?– Fox
4 hours ago
1
1
export SOMEDIR="/var/www/site"; cd "$SOMEDIR/app"
– RoVo
4 hours ago
export SOMEDIR="/var/www/site"; cd "$SOMEDIR/app"
– RoVo
4 hours ago
@Fox ah of course, can't believe I missed that ... could I add it to the alias, e.g.
somedir/app
? (tried: answer no xD)– ThisGuyHasTwoThumbs
4 hours ago
@Fox ah of course, can't believe I missed that ... could I add it to the alias, e.g.
somedir/app
? (tried: answer no xD)– ThisGuyHasTwoThumbs
4 hours ago
@RoVo I suppose that makes sense, create it as a var and then can use within the cd - ty :)
– ThisGuyHasTwoThumbs
4 hours ago
@RoVo I suppose that makes sense, create it as a var and then can use within the cd - ty :)
– ThisGuyHasTwoThumbs
4 hours ago
Also look up cdable vars and autocd in the bash manual (not sure if they can be combined, but one of them maybe useful)
– muru
3 hours ago
Also look up cdable vars and autocd in the bash manual (not sure if they can be combined, but one of them maybe useful)
– muru
3 hours ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
4
down vote
accepted
The bash
shell has a CDPATH
shell variable that helps you do this without an alias:
$ CDPATH=".:/var/www/site"
$ cd app
/var/www/site/app
If there's a subdirectory of app
called doc
:
$ cd app/doc
/var/www/site/app/doc
With a CDPATH
value of .:/var/www/site
, the cd
command will first look in the current directory for the directory path given on the command line, and if none is found it will look under /var/www/site
.
From the bash
manual:
CDPATH
The search path for the
cd
command. This is a colon-separated
list of directories in which the shell looks for destination
directories specified by thecd
command. A sample value is
".:~:/usr"
.
Note that CDPATH
does not need to be exported.
awesome thank you
– ThisGuyHasTwoThumbs
2 hours ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
The bash
shell has a CDPATH
shell variable that helps you do this without an alias:
$ CDPATH=".:/var/www/site"
$ cd app
/var/www/site/app
If there's a subdirectory of app
called doc
:
$ cd app/doc
/var/www/site/app/doc
With a CDPATH
value of .:/var/www/site
, the cd
command will first look in the current directory for the directory path given on the command line, and if none is found it will look under /var/www/site
.
From the bash
manual:
CDPATH
The search path for the
cd
command. This is a colon-separated
list of directories in which the shell looks for destination
directories specified by thecd
command. A sample value is
".:~:/usr"
.
Note that CDPATH
does not need to be exported.
awesome thank you
– ThisGuyHasTwoThumbs
2 hours ago
add a comment |Â
up vote
4
down vote
accepted
The bash
shell has a CDPATH
shell variable that helps you do this without an alias:
$ CDPATH=".:/var/www/site"
$ cd app
/var/www/site/app
If there's a subdirectory of app
called doc
:
$ cd app/doc
/var/www/site/app/doc
With a CDPATH
value of .:/var/www/site
, the cd
command will first look in the current directory for the directory path given on the command line, and if none is found it will look under /var/www/site
.
From the bash
manual:
CDPATH
The search path for the
cd
command. This is a colon-separated
list of directories in which the shell looks for destination
directories specified by thecd
command. A sample value is
".:~:/usr"
.
Note that CDPATH
does not need to be exported.
awesome thank you
– ThisGuyHasTwoThumbs
2 hours ago
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
The bash
shell has a CDPATH
shell variable that helps you do this without an alias:
$ CDPATH=".:/var/www/site"
$ cd app
/var/www/site/app
If there's a subdirectory of app
called doc
:
$ cd app/doc
/var/www/site/app/doc
With a CDPATH
value of .:/var/www/site
, the cd
command will first look in the current directory for the directory path given on the command line, and if none is found it will look under /var/www/site
.
From the bash
manual:
CDPATH
The search path for the
cd
command. This is a colon-separated
list of directories in which the shell looks for destination
directories specified by thecd
command. A sample value is
".:~:/usr"
.
Note that CDPATH
does not need to be exported.
The bash
shell has a CDPATH
shell variable that helps you do this without an alias:
$ CDPATH=".:/var/www/site"
$ cd app
/var/www/site/app
If there's a subdirectory of app
called doc
:
$ cd app/doc
/var/www/site/app/doc
With a CDPATH
value of .:/var/www/site
, the cd
command will first look in the current directory for the directory path given on the command line, and if none is found it will look under /var/www/site
.
From the bash
manual:
CDPATH
The search path for the
cd
command. This is a colon-separated
list of directories in which the shell looks for destination
directories specified by thecd
command. A sample value is
".:~:/usr"
.
Note that CDPATH
does not need to be exported.
edited 2 hours ago
answered 2 hours ago


Kusalananda
110k15215340
110k15215340
awesome thank you
– ThisGuyHasTwoThumbs
2 hours ago
add a comment |Â
awesome thank you
– ThisGuyHasTwoThumbs
2 hours ago
awesome thank you
– ThisGuyHasTwoThumbs
2 hours ago
awesome thank you
– ThisGuyHasTwoThumbs
2 hours ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f476972%2fuse-alias-and-carry-it-on%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
3
Even if aliases were expanded in operand positions this wouldn't do what you want, you'd end up with
cd cd /var/www/site/app
(note the doublecd
). Why not just use a variable?– Fox
4 hours ago
1
export SOMEDIR="/var/www/site"; cd "$SOMEDIR/app"
– RoVo
4 hours ago
@Fox ah of course, can't believe I missed that ... could I add it to the alias, e.g.
somedir/app
? (tried: answer no xD)– ThisGuyHasTwoThumbs
4 hours ago
@RoVo I suppose that makes sense, create it as a var and then can use within the cd - ty :)
– ThisGuyHasTwoThumbs
4 hours ago
Also look up cdable vars and autocd in the bash manual (not sure if they can be combined, but one of them maybe useful)
– muru
3 hours ago