Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 334
  • Last Modified:

multiple commands on a single alias

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'
0
Axter
Asked:
Axter
2 Solutions
 
liddlerCommented:
alias mcd='cd /devt/vbs/ncr;ct co -nc'
or
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
0
 
jlevieCommented:
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.
0
 
sunnycoderCommented:
Hi Axter,

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

second will be executed only if first is successful

Sunnycoder
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
sunnycoderCommented:
doh ... sorry for the repetition of idea ... My network is not behaving very well today :-(
0
 
JustsolutionsCommented:
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.
0
 
AxterAuthor Commented:
Thanks for the very quick response... :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Tackle projects and never again get stuck behind a technical roadblock.
Join Now