linuxbashpath-variables

Get and print directories from $PATH in bash


The script that I have to write must find the directories from the $PATH variable and print only the ones that end with an i.

How am I thinking about doing it

Problems

Any ideas on how to get over this problem,or can you think of something more appropriate.


Solution

  • You can use this BASH one-liner for that job:

    (IFS=':'; for i in $PATH; do [[ -d "$i" && $i =~ i$ ]] && echo "$i"; done)