Given an input variable say usr/bin and the following PATH
/usr/local/bin /usr/bin /bin /usr/sbin /sbin /usr/local/sbin /Developer/bin
for x in $list
if [ $x = $argv ]
//delete element x from list -> How?
This is rather easy to do in fish.
set -e, you can erase not just entire variables, but also elements from lists, like
set -e PATH to delete the second element (fish counts list indices from 1).
contains -i, you can find which index an element is at.
So you'll want to call
set -e PATH[(contains -i $argv $PATH)].
With some error-handling and edgecases fixed, this'd look like
function deleteFromPath # This only uses the first argument # if you want more, use a for-loop # Or you might want to error `if set -q argv` # The "--" here is to protect from arguments or $PATH components that start with "-" set -l index (contains -i -- $argv $PATH) # If the contains call fails, it returns nothing, so $index will have no elements # (all variables in fish are lists) if set -q index set -e PATH[$index] else return 1 end end
Note that this compares the path strings, so you'd need to call
deleteFromPath /usr/bin, with the leading "/". Otherwise it would not find the component.