Re: Bash – am I getting MAD here?
Johnny Rosenberg
gurus.knugum at gmail.com
Wed Jul 27 19:04:28 UTC 2016
2016-07-27 20:55 GMT+02:00 Paul Smith <paul at mad-scientist.net>:
> 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).
>
Oh, I didn't think of that. I use that syntax sometimes for temporary
values of IFS. I should have thought of that. Thanks for the suggestion, it
also makes the function look better…
I tested this and, of course, it works too.
Kind regards
Johnny Rosenberg
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20160727/ef1802c0/attachment.html>
More information about the ubuntu-users
mailing list