how can I display all the paths from $PATH like this?
Path 1: usr/bin
Path 2: /bin
... and so on.
I'm very new to this so I have no idea what to do with grep and how to display it like this. Thx in advance
I'm not quite sure why you want this? tr
can translate character:
$ echo "$PATH" | tr ':' $'\n'
/usr/bin
/bin
...
tr
will translate SET1 (:
) to SET2 (newlines)
Alternative you can use AWK to format it a little nicer:
$ awk '{ print "Path: "NR, $0 }' RS=: <<< "$PATH"
Path 1: /usr/bin
Path 2: /bin
...
In a shell script you could do this:
#!/bin/bash
IFS=':' read -ra ITEMS <<< "$PATH"
for i in "${ITEMS[@]}"; do
echo "$i"
done
This will print out each individual PATH setting in the list on a separate line.
If you want to do something else with it you just change the command(s) inside the for
loop.
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