[Techtalk] command aliasing

Hamster hamster at hamsternet.org
Sat Mar 30 13:42:15 EST 2002


> Hi everyone,  I'm in need of a little nudge int he right direction...

nudge :)

> Currently,  when I compile something, I need to issue the following
> command;
> 
> g++ inputfilename -o /home/lyric340/bin/application
> 
> what I was hoping to do was to alias this command with a variable for
> inputfilename that would allow me to do this;
> 
> compile inputfilename
> 
I am sure there are a million possible solutions to this, but here is one I though of :)

Its a bash script :) 

#!/bin/bash

#usage: compile inputfilname

#this portion of codes makes sure that the user enters the input filename
#If this variable isnt given, then print usage guide and exits.

if [ $# -ne 1 ]
then
	echo "Usage: compile NameOfInputFilename"
	exit 1
fi

#if the programme gets this far (ie the input filename is given) then execute the #g++ command

g++ $1 -o /home/lyric340/bin/application

#end of programme---

What you need to do is copy and paste this in a plain text editor, save it as compile
in a directory that its in your path. Possibly /usr/bin ?
and do a 
chmod a+x /path/to/compile
(this makes it executable)
and it should work :)

Hope this is of some use to you!
If you try it and get some error, let me know - I've probably just made a typo somewhere.

Hamster





More information about the Techtalk mailing list