If I type echo $PATH
in the terminal I get the following result:
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/fnorbert/.local/bin:/home/fnorbert/bin
I want to iterate over these paths using a shell script, but I do not know how to do that.
I tried the following:
for i in 1 2 3
do
echo $PATH | cut -d':' -f$i
done
This prints the first three paths, but I want to represent every path with the variable i
if it is possible.
You can use read
with delimiter set as :
while read -d ':' p; do
echo "$p"
done <<< "$PATH:"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With