Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

where

alias='binary2 options2'

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

share|improve this question

migrated from stackoverflow.com Jun 5 '13 at 15:47

This question came from our site for professional and enthusiast programmers.

    
If what you really want them to type is something like: binary1 optionset1 binary2 and have it become: binary1 optionset1 binary2 optionset2 where optionset2 is what YOU define then what you really need to fake is binary1; but in the comments below you said that you cannot choose what binary1 is. Is that correct? –  Ahmed Masud Jun 5 '13 at 12:38
    
I need binary1 to be mpirun and options1 to be -np $NPROCS (where NPROCS is the number of processors and its value is retrieved from the environment). Then comes binary2, called dplace and the options (options2) are -s1 -c 0-$TOP_PROC (being $TOP_PROC=$NPROC-1). Currently users use the command: mpirun -np $NPROCS dplace application_executable_binary. I want to introduce the options for dplace in a transparent way so the have not to change the way they submit jobs to the queue. Thank you! –  Jakob Bach Jun 5 '13 at 12:50
    
Okay there is a bit more confusion on my part; I want to understand this correctly: You want the user to type mpirun -np $NPROCS someapp and inject dplace options2 between 'someapp' transparently so it becomes: mpirun -np $NPROCS dplace -s1 -c 0-$TOP_PROC someapp –  Ahmed Masud Jun 5 '13 at 12:56
    
I want the users to type mpirun -np $NPROCS dplace someapp. I want dplace to appear explicitly, that is, want them to type what they have been typing so far. That's why I need to introduce those options in "silent mode". Thank you! (I could do it in C, but I wonder if it can be done via shell scripting). –  Jakob Bach Jun 5 '13 at 13:05
add comment

2 Answers

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
share|improve this answer
    
Yes, binary1 and options1 have to be whatever they want. It is a good approach, thank you. However I would like to make the transition completely transparent for the users (they do not specify options2 now). Thus, if they need to invoke the function first it does not serve my purpose. –  Jakob Bach Jun 5 '13 at 12:06
    
However, tweaking it a little bit, playing with aliases and fuctions might serve my purpose. –  Jakob Bach Jun 5 '13 at 12:12
    
I can't see how binary1, if really it can be whatever they want, can handle the call of an alias ... That's why I propose to put the alias (or, rather, function, as it's more flexible) in front instead of as an argument. And they do NOT need to know options2 at all, if you see: $your_options is defined in the function (or at the same time), by you. I changed the name tp "options2" and gave an example of definition (in the function itself, but could be external) –  Olivier Dulac Jun 5 '13 at 13:06
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.