[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: a command with a long list of options



Hi,

rlharris@oplink.net wrote:
> enscript --verbose --media=letter -2 --landscape --borders --header='$n|A.D. $D{%Y.%m.%d}|$* gmt | Page $% of $=' filename
> ...
> can I define in bash an alias or something

The job is somewhat too big for a bash alias.
But there is the old concept of a shell script.

Use your favorite text editor to open a file in your
$HOME directory. E.g.:

  vi ~/my_enscript

Write as first line the address of the program that shall
interpret your script. Prepend it by "#!" :

  #!/bin/bash

Then write your command line, replacing the filename by "$1"

  enscript --verbose --media=letter -2 --landscape --borders \
           --header='$n|A.D. $D{%Y.%m.%d}|$* gmt | Page $% of $=' \
           "$1"

(I split the long line by backslashes for better readbility.)

Store the file and leave the editor.
Back in the shell give the file x-permission for its owner:

  chmod o+x ~/my_enscript

To run your script with file "filename", execute in the shell

  ~/my_enscript filename

"$1" in the script will get replaced by the first argument of your
command line. I.e by "filename".


Have a look at your shell variable $PATH. It tells a list of
directories where scripts and programs are looked up if their
name contains no "/".

  echo $PATH

might put out something like

  /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/thomas/bin

So if i would put "my_script" into /home/thomas/bin then it would
be found by bash without the leading "~/":

  my_enscript filename


Have a nice day :)

Thomas


Reply to: