How do I make an alias work when I need to invoke more than one binary in the same command?

Posted on

Problem :

Say I have two binary files: binary1 and binary2.

Each of them has its own option set: options1 and options2.

Users need to invoke a command that follows this structure:

binary1 options1 binary2 options2

However, I want to set options2 myself and make them run the following:

binary1 options1 alias


alias='binary2 options2'

Is there any way to make this work under bash/tcsh? I am working under SLES 11 SP2 over 64bit architecture.

Solution :

You need to have binary1 and options1 be whatever they want to start?
Then : define the function “something” :

something () {
   options2="...." #you define them as you want, either here or from another source
   binary1="$1" ; shift
   "$binary1" "$@"
   binary2  $options2

(and have it defined in the bash login files)

And have them run :

something binary1 options1

That way they can really go nuts on options1, such as:

something touch file1 file2 "file3 with extra spaces" file4

mpirun does not like to run an alias, as you have probably figured out alread. Best thing is to create a wrapper around your executable. So place the following in a file (make it executable):

#!/usr/intel/bin/tcsh -f
exec /full/path/to/dplace -s1 -c 0-$TOP_PROC $*

If you name this file “dplace” and place it in the users’ path in a directory which is searched ahead of the directory where the real dplace is found, then it will transparently run the wrapper script instead (remember to “rehash” as you are trying this out).

I assume TOP_PROC is already defined in the enviroment.

Leave a Reply

Your email address will not be published. Required fields are marked *