Monday, June 09, 2008

bash: creating an alias with an argument

This is something I've thought would be useful for a while, but I never got around to figuring out how to do it. We have a command we use frequently at work for configuring the sun one application server, glassfish - asadmin. The asadmin command takes the command and then some arguments eg:
asadmin deploy --target instance1 --user admin --passwordfile /home/whatever/.password dist/application.ear

The bold bits tend to be common with only the italic bits changing. This is how to set up an alias in bash:
edit ~/.bashrc and add the line:
aa () { asadmin $1 --target instance1 --user admin --passwordfile /home/whatever/.password $2 $3 $4 $5; }

After logging out and in, you will have a new command called 'aa' which you can use like:
aa deploy dist/application.ear

Now, that's easier, isn't it?

No comments: