Use alias and carry it on

The name of the pictureThe name of the pictureThe name of the pictureClash 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?










share|improve this question

















  • 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







  • 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














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?










share|improve this question

















  • 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







  • 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












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?










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 with cd cd /var/www/site/app (note the double cd). 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




    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




    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










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 the cd command. A sample value is
".:~:/usr".




Note that CDPATH does not need to be exported.






share|improve this answer






















  • awesome thank you
    – ThisGuyHasTwoThumbs
    2 hours ago










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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 the cd command. A sample value is
".:~:/usr".




Note that CDPATH does not need to be exported.






share|improve this answer






















  • awesome thank you
    – ThisGuyHasTwoThumbs
    2 hours ago














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 the cd command. A sample value is
".:~:/usr".




Note that CDPATH does not need to be exported.






share|improve this answer






















  • awesome thank you
    – ThisGuyHasTwoThumbs
    2 hours ago












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 the cd command. A sample value is
".:~:/usr".




Note that CDPATH does not need to be exported.






share|improve this answer














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 the cd command. A sample value is
".:~:/usr".




Note that CDPATH does not need to be exported.







share|improve this answer














share|improve this answer



share|improve this answer








edited 2 hours ago

























answered 2 hours ago









Kusalananda

110k15215340




110k15215340











  • awesome thank you
    – ThisGuyHasTwoThumbs
    2 hours ago
















  • awesome thank you
    – ThisGuyHasTwoThumbs
    2 hours ago















awesome thank you
– ThisGuyHasTwoThumbs
2 hours ago




awesome thank you
– ThisGuyHasTwoThumbs
2 hours ago

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Comments

Popular posts from this blog

List of Gilmore Girls characters

What does second last employer means? [closed]

One-line joke