multiple commands on a single alias

Posted on 2004-08-31
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 18

Accepted Solution

liddler earned 1200 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 800 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

800 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