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

Re: a command with a long list of options


> I write and use bash scripts almost daily,

I did not know that you were tired and thus did not come
to the idea of a script yourself. So you got the mini starter
for scripters. My programs are similarly unusable as enscript
if one does not develop their serious jobs in scripts.

> The only additional thing
> for which I had to google was the procedure for modifying PATH.

What did you add there ?

I would have rather moved the script to one of the directories
which were already listed in PATH. Or staid with the inconvenience
to always prepend "~/" to its name.

> needed to include the rest of the command line (the file name); I was
> not sure that that could be done in bash.

We have a wide variety of variable parameters in bash.
Execute man bash, search for "Positional Parameters" and
also read the next chapter "Special Parameters".

If you just want to forward all arguments unchanged to
enscript, then replace "$1" by "$@" (with quotation marks).
The form "$@" makes least trouble with blanks or special
characters in the arguments.

Play with this test script ~/my_test:


  for i in "$@"
    echo ">>> $i <<<"

Give it something to gnaw on

  ~/my_test a 'b B' 'New

should put out

  >>> a <<<
  >>> b B <<<
  >>> New
  line <<<

You may also send named parameters to a script:

  file=/my/file/name ~/my_script ...maybe.some.arguments...

to be used inside the script as variable by prefix "$"
and typically inside "-quotes to keep blanks from splitting


  echo "file : $file"

This should put out with above run

  file : /my/file/name

Then there are the exported variables

  export file=/my/file/name

  ... maybe other shell commands ...

  ~/my_script ...

The script will then know the variable content of "$file".

Be aware that Debian by default uses /bin/dash for executing
shell scripts, if they start by
dash offers less extras than bash. It is desirable to stay
away from "bashisms" as long as one does not really need them.

So maybe it is wise to change
in order to notice when bashisms sneak into your scripting.

Have a nice day :)


Reply to: