Re: problem setting the PATH variable.

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

 



On 25Mar2020 05:31, Angelo Moreschini <mrangelo.fedora@xxxxxxxxx> wrote:
I couldn't understand the reason for the double registration of the path :
(surly the script was executed twice).

Or the same incantation is elsewhere in your setup, thus doing it twice. Eg .profile or something.

I write (for the benefit of others) the solution I found:
(I modified the script with a condition).

---------
newpath="/opt/netbeans/java/maven/bin"

No quotes needed here.

if [[ "$PATH" != *"$newpath"* ]]; then

This is a little fuzzy. It is conceivable (though in this case unlikely) that your $PATH contains something like:

   /something/opt/netbeans/java/maven/bin

or:

   /opt/netbeans/java/maven/bin-other-thing

and your match would mistakenly thing the path:

   /opt/netbeans/java/maven/bin

was present. Personally I am old school and do this with a case statement (though the same can be applied with [[....]]):

   case ":$PATH:" in
       *":$newpath:"*)
           # already present
           ;;
       *)  PATH=$PATH:$newpath
           export PATH
           ;;
   esac

The important thing here isn't case vs [[....]], it is the ":" bracketing of $PATH and $newpath to avoid accidentally matching a longer string which just happens to contain $newpath.

   PATH=$PATH:/opt/netbeans/java/maven/bin

Use $newpath here, avoids writing the maven path twice:

   PATH=$PATH:$newpath

   export PATH
fi

But the incantation is being run twice. How that is happening seems worth investigating when you're idle and bored.

Elsewhere in the thread someone mentioned some presupplied shell function for
adding to $PATH which contains essentially the logic in your if-statement.

Cheers,
Cameron Simpson <cs@xxxxxxxxxx>
_______________________________________________
users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/users@xxxxxxxxxxxxxxxxxxxxxxx



[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux