Bash functions to modify PATH
Quoting

You should double-quote variables that may contain spaces when used as command arguments. For example here:


addToPath $element false NEW_PATH



You will get strange results if $element contains spaces. Double-quote it, and also in the conditional inside the function:

if [ ! -d "$1" ]; then 


One statement per line

It's easiest to read code from top to bottom,
without having to carefully read from left to write too. For this reason it would be better to split the conditionals you crammed on a single line.

Simple solutions are better

The optional third parameter of the function is quite clever, appending to a specified variable instead of the default, at the expense of some added complexity. Instead of all that, you could simply reset PATH after setting path_array and before calling the function. That way you could get rid of the third parameter of the function and its added complexity.

Note also that your function does not add duplicates. So instead of removing duplicates at the end, it will be better to remove duplicates at the beginning, as that will process fewer path elements.

case with two cases

When a switch-construct is used with only two cases,
it's usually easier to read converted to an if-else.