thanks for the tips ..
I don't have  experience writing bash scripts, (writing them is torture because I'm always wrong ...;-)  ),
.....I only copied the check of substrings from an example.

You was very kind with your suggestions , and I will bring the improvements you  suggested  me :-).

Regarding the use of the condition, <if>, in my opinion this is an excellent solution (because it is practical and really efficient) so no matter about how the setup works,
Thanks again .

Angelo

On Wed, Mar 25, 2020 at 6:46 AM Cameron Simpson <cs@cskk.id.au> wrote:
On 25Mar2020 05:31, Angelo Moreschini <mrangelo.fedora@gmail.com> 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@cskk.id.au>
_______________________________________________
users mailing list -- users@lists.fedoraproject.org
To unsubscribe send an email to users-leave@lists.fedoraproject.org
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@lists.fedoraproject.org