[comp.unix.questions] Simple shell procedure

wizard@chemstor.uoregon.edu (KevinS) (07/09/90)

Hello Netters, I have a need for a simple shell procedure that replaces
a command line like :

program < datafile.in > datafile.out

So that all I have to do is type:

shellprocedure datafile

And the shell procedure will append the suffix ".in" (if the filename
passed to the script doesn't already have it) and also append an
".out" to the filename used for the redirected output.

Thanks


Kevins@ori.org

weinelt@sbsvax.cs.uni-sb.de (Bernhard Weinelt) (07/10/90)

In article <WIZARD.90Jul8205942@chemstor.uoregon.edu>, wizard@chemstor.uoregon.edu (KevinS) writes:
> 
> Hello Netters, I have a need for a simple shell procedure that replaces
> a command line like :
>                       program < datafile.in > datafile.out
> So that all I have to do is type:
>                       shellprocedure datafile
> 
> Kevins@ori.org

If you are using /bin/csh, you do not need a shellprocedure, try an alias:
  alias start 'program <\!:1*.in >\!:1*.out'      and type   start datafile

In case of /bin/sh (or /bin/csh as well) the content of the shellprocedure
may look like
  program <$1.in >$1.out                     then type shellprocedure datafile

Both solutions are trivial; take a look of the manual and you will find 
how to use shell variables (from the command line, in your case).

Many Greetings         Bernhard
-- 
                                         ------------------------------------
                  __________________     | Bernhard Weinelt                 |
         (__)    /                  \    | Universitaet des Saarlandes      |
         (oo)   (    Many Greetings  )   | FB 14 - Informatik (Dept. of CS) |
  /-------\/  --'\__________________/    | Bau 36, Im Stadtwald 15          |
 / |     ||                              | D-6600 Saarbruecken 11, W-Germany|
*  ||----||                              | weinelt@cs.uni-sb.de             |
   ~~    ~~                              ------------------------------------

jrw@mtune.ATT.COM (Jim Webb) (07/10/90)

In article <WIZARD.90Jul8205942@chemstor.uoregon.edu>, wizard@chemstor.uoregon.edu (KevinS) writes:
? 
? Hello Netters, I have a need for a simple shell procedure that replaces
? a command line like :
? 
? program < datafile.in > datafile.out
? 
? So that all I have to do is type:
? 
? shellprocedure datafile
? 
? And the shell procedure will append the suffix ".in" (if the filename
? passed to the script doesn't already have it) and also append an
? ".out" to the filename used for the redirected output.
? 
? Thanks
? 
? 
? Kevins@ori.org

A one line approach:

[ "${1?No datafile}" ] && exec program <`expr $1 : '\(.*\).in' \| $1`.in >`expr $1 : '\(.*\).in' \| $1`.out

:-)

-- 
Jim Webb                "Out of Phase -- Get Help"               att!mtune!jrw
                  "I'm bored with this....Let's Dance!"