I'm trying to write a couple of shortcut aliases to quickly navigate to the httpdocs folders of the various domains and subdomains on my server. basically so I can type something like:
$ pwd
/
$ # Go to the 'site.com' domain:
$ goto site.com
$ pwd
/var/www/vhosts/site.com/httpdocs
$ # Go to the 'subsite' subdomain:
$ gotosub site.com subsite
$ pwd
/var/www/vhosts/site.com/subdomains/subsite/httpdocs
I'm pretty green when it comes to Linux commands and I've tried to research this but failed at putting together search terms that have helped.
I've tried using printf and backticks like this:
$ alias goto='`printf "cd /var/www/vhosts/%s/httpdocs"`'
$ alias gotosub='`printf "cd /var/www/vhosts/%s/subdomains/%s/httpdocs"`'
but that doesn't replace in the arguments. If I remove the backticks:
$ alias goto='printf "cd /var/www/vhosts/%s/httpdocs"'
$ alias gotosub='printf "cd /var/www/vhosts/%s/subdomains/%s/httpdocs"'
Then it works but I need to run them like so:
$ `goto site.com`
$ `gotosub site.com subsite`
...Which seems ugly and inefficient. What's the best approach to achieve this?
I've tried using the '<' operator to do this but haven't been able to make it work.
– P-Q Jan 23 '14 at 11:17