multiple commands on a single alias

Posted on 2004-08-31
Last Modified: 2010-04-21
Can I setup multiple commands on a single alias.
For example, I want to have one alias that changes the directory, and launches an executable with specific parameters.

How can I do that, and what are the syntax for it?

alias mcd='cd /devt/vbs/ncr' 'ct co -nc'
Question by:Axter
LVL 18

Accepted Solution

liddler earned 300 total points
ID: 11942160
alias mcd='cd /devt/vbs/ncr;ct co -nc'
alias mcd='cd /devt/vbs/ncr && ct co -nc'
the && makes sure the first command returns without an error before trying the second, the first just runs them one after other
LVL 40

Assisted Solution

jlevie earned 200 total points
ID: 11942211
In this case you could also do:

alias mcd="(cd /devt/vbs/ncr; ct co -nc)"

That will execute the change dir & command in a subshell which won't change the current working directory.
LVL 45

Expert Comment

ID: 11942248
Hi Axter,

yes you can
alias mcd='cd /devt/vbs/ncr && ct co -nc'

second will be executed only if first is successful

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

LVL 45

Expert Comment

ID: 11942257
doh ... sorry for the repetition of idea ... My network is not behaving very well today :-(

Expert Comment

ID: 11942267
One other thing to be careful with.  The use of " or ' makes a BIG difference with
command substitution in your shell.  " allows variable substitution, ' does not.
LVL 30

Author Comment

ID: 11942377
Thanks for the very quick response... :-)

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap ( Version 1.2 2.      Jpcap( Version 0.6 Prerequisite: 1.      GCC …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question