Bash – am I getting MAD here?

Paul Smith paul at mad-scientist.net
Wed Jul 27 18:55:16 UTC 2016


On Wed, 2016-07-27 at 20:48 +0200, Johnny Rosenberg wrote:
> Having another look at my ToURI function, I'm also wondering if
> ”export local” is meaningful. Sounds like a contradiction… But I need
> the export for the perl thing at the end of the function, I don't
> think it will work otherwise.

You don't need to do that.  Just put the variable before the command
invocation:

  ToURI () {
    FileName="$1" perl -MURI::file -e 'print URI::file->new($ENV{'FileName'})."\n"'
  }

In shell syntax you can set an environment variable to be in effect
only for a given command by putting it on the same command line, before
the command:

  VAR1=val [VAR2=val ...] command ...

Much safer and more portable (works in all variations of POSIX sh).



More information about the ubuntu-users mailing list