A script to show PATH

Here you can exchange scripts that you created or have permission to share with other users.
Message
Author
Jakob77
Posts: 651
Joined: Thu Feb 09, 2023 3:09 am

A script to show PATH

#1 Post by Jakob77 »

This is a little script that can be used in MX23 Xfce (and likely others) for showing and testing PATH

I name it "showpath" but some would add the extension ".sh" and claim it to be safer:

Code: Select all

showpath.sh

Code: Select all

#!/bin/bash
echo $PATH >> ~/PATH_log.txt
date +Kl-%R-%d-%b-%Y >> ~/PATH_log.txt
echo "" >> ~/PATH_log.txt
featherpad + ~/PATH_log.txt

It will create the file "~/PATH_log.txt" and add the PATH and time to it and open it with Featherpad, so you can see it and compare to the last time you did it. And you can add a comment if you want.

If you prefer an other editor you can just edit the last line.
For instance a command for Gedit is very similar:

Code: Select all

gedit + ~/PATH_log.txt
Other suggestions are welcome.


How to use.?
In user friendly scripting a scriptor must have his PATH under full control, so I choose always to have an icon for it in my panel.
And if I ever have doubts about if PATH is working correctly in Terminal I just execute the command "showpath.sh" in Terminal.
It shows what the PATH is not before or after but in the very moment when the script is actually running.

If you use Xfce, and you have a directory for your personal scripts I can recommend a test. Especially with the command "showpath.sh" put into a desktop program launcher, and also one in the Panel. Then you can start easy testing from different locations. From desktop, from Panel, from Terminal, when Live, from another user profiles, and where else you might want.
Afterwards you perhaps decide to reconfigure PATH and/or move the script to another directory and try it all over again.

The script is still pure code just made for testing.
In case more explanation is demanded I will do my best to supply. :-)




****Edit:

On basis of the discussion, and in order to promote a user friendly MX script culture, I have upgraded the script with a help sequence, more text, and output from "whereis" is being added to the log file:

Code: Select all

#!/bin/bash
# This script is a testscript for finding script location and PATH and log it in a file that is automatically opened by Featherpad showing the result.
# The script is a user built in MX-Linux 23
# Ref. https://forum.mxlinux.org/viewtopic.php?p=822108#p822108
# Ref. script template: https://forum.mxlinux.org/viewtopic.php?p=725990#p725990


# Main sequence begin

case $1 in


# Subsequence begin

    'show'|'run')

# Sending empty line to ~/PATH_log.txt
	echo "" >> ~/PATH_log.txt
# Sending output from "whereis" to ~/PATH_log.txt
	whereis "${0##*/}" >> ~/PATH_log.txt
# Sending info, date and time to ~/PATH_log.txt
	date +'Execution moment:  '%R-%d-%b-%Y >> ~/PATH_log.txt
# Sending PATH to ~/PATH_log.txt
	echo $PATH >> ~/PATH_log.txt
# Sending empty line to ~/PATH_log.txt
	echo "" >> ~/PATH_log.txt
# Open ~/PATH_log.txt with Featherpad going to end of file
	featherpad + ~/PATH_log.txt

        ;;

# Subsequence end
# Subsequence begin

    'help'|'-h'|'-help'|'--help'|'-?'|'--?'|'/?')

    	clear
        echo "Purpose: - Showing and logging PATH"
        echo "Create ~/PATH_log.txt - put PATH in it and open it with Featherpad"
        echo "Test for script PATH at chosen location when script is running"
        echo 'If needed there is more info. inside the script'
        echo "Syntaks: ['${0##*/}'] [Argument]"
        echo ''
        echo ''
        echo 'Arguments:'
        echo '  --help       This help text'
        echo '  show         Send PATH to ~/PATH_log.txt and open with Featerpad'
        echo ''
        echo 'Exampels:'
        echo '  "'${0##*/}' --help"   Show this help'
        echo '  "'${0##*/}' show"     Run the test'
        ;;

# Subsequence end
# Below this line you will find commands that are used if no argument has previously been recognized.
    *)

# The next line will make the script run 'show' even without the argument 
	"${0##*/}" show
# If deactivated it might be relevant instead to activate this line: 
#         echo ' Write "'${0##*/}' --help" for help'

        ;;
# Above this line you will find commands that are used if no argument has previously been recognized.

esac

# Main sequence end
Last edited by Jakob77 on Thu Jun 12, 2025 3:08 pm, edited 1 time in total.

User avatar
DukeComposed
Posts: 1390
Joined: Thu Mar 16, 2023 1:57 pm

Re: A script to show PATH

#2 Post by DukeComposed »

Jakob77 wrote: Wed Jun 11, 2025 8:08 am It will create the file "~/PATH_log.txt" and add the PATH and time to it and open it with Featherpad, so you can see it and compare
Why do these steps need to occur? How is this better than "echo $PATH"? What happens when two processes run the same script simultaneously? How does the file get locked in a mutually exclusive way?
Jakob77 wrote: Wed Jun 11, 2025 8:08 am And if I ever have doubts about if PATH is working correctly in Terminal I just execute the command
Why would there be doubts about an environment variable? Environment variables in practice don't change very much and PATH, in particular, shouldn't change very often, if at all. If you need an variable set in a script, you set it, definitively, and then run the logic of your software. I find I may edit PATH globally once on installing a new machine, or if I add new software that installs to a location in /opt or something. It is not a daily, weekly, or even bi-annual quandary.

If you're just going to reject any critique of this script, as you've typically done before, why are you sharing it now? This is a public forum. Surely you understand that posting snippets of shell script are going to solicit feedback or criticism you neither want to hear nor will accept or use. You've been harping on this editing PATH project for two years and so far as I know you're the only person who's worrying about this, or who cares so deeply about what PATH contains from moment to moment. Can you please explain what this morbid fixation is all about?

Do you want a cookie? A compliment? Good job. You learned how to cat things to a text file. I cannot fathom why you have felt the need to share so many variations on this theme with the class for so long. Your last thread about ~/bin and PATH got closed, as did the one from 2023 you recently bumped, and this thread just stinks of trying to pull the same stunt sideways. Your little snippets of shell aren't benefiting the community. They aren't making you a better programmer, user, or sysadmin. And they aren't very useful for teaching others how to write Bash.

Jakob77
Posts: 651
Joined: Thu Feb 09, 2023 3:09 am

Re: A script to show PATH

#3 Post by Jakob77 »

DukeComposed

It is just a simple test script to do a specific test job. If you have a better one for the same job, how about bringing it on and let's have some fun instead.? :-)

I could make a help sequence for it and maybe I will but I suppose the subject here can provide the help needed.
In my opinion it is so harmless and simple self explaining that it is not needed much but if anyone thinks differently I am actually all with them as a matter of principal about good user friendly scripting culture. :-)

User avatar
DukeComposed
Posts: 1390
Joined: Thu Mar 16, 2023 1:57 pm

Re: A script to show PATH

#4 Post by DukeComposed »

Jakob77 wrote: Wed Jun 11, 2025 1:50 pm how about bringing it on and let's have some fun instead.?
"Don’t ever wrestle with a pig. You’ll both get dirty but the pig will enjoy it."

User avatar
richb
Administrator
Posts: 10890
Joined: Wed Jul 12, 2006 2:17 pm

Re: A script to show PATH

#5 Post by richb »

Tone down commentary.
Forum Rules
Guide - How to Ask for Help

richb Administrator
System: MX 23 KDE
AMD A8 7600 FM2+ CPU R7 Graphics, 16 GIG Mem. Three Samsung EVO SSD's 250 GB

User avatar
Melber
Developer
Posts: 1303
Joined: Tue Mar 23, 2021 4:19 pm

Re: A script to show PATH

#6 Post by Melber »

If I had an inexplicable need to constantly check the contents of PATH, and for some other reason was averse to just typing echo $PATH into a terminal, in xfce I would do something like

1. right click on desktop to create a launcher
2. enter something like "Check Path" in the "Name" field
3. paste the following in the "Command" field

Code: Select all

bash -c 'jakob="$(echo $PATH | sed -e "s/\:/\\n/g")"; yad --title="Path" --width=200 --text="$jakob" --button="OK"; exit'
4. Click Save
and just use the launcher.

but luckily I've never edited PATH and hence have no reason to check its contents.

User avatar
siamhie
Global Moderator
Posts: 3338
Joined: Fri Aug 20, 2021 5:45 pm

Re: A script to show PATH

#7 Post by siamhie »

How does it test the $PATH?
This is my Fluxbox . There are many others like it, but this one is mine. My Fluxbox is my best friend. It is my life.
I must master it as I must master my life. Without me, my Fluxbox is useless. Without my Fluxbox, I am useless.

Jakob77
Posts: 651
Joined: Thu Feb 09, 2023 3:09 am

Re: A script to show PATH

#8 Post by Jakob77 »

Thank you for your answers. I see some ignorance that tells me even more how needed this is for users who wants to do user friendly scripting with good functionality.
It is not a new story in Linux. In DOS it was very simple and clear.
The need for a PATH is still as simple and important but being able to obtain the same config control and reliability in Linux has always been a problem in all the two other distros I have digged in to before. That is more than 10 years I have been looking at that poor frustrating mess.
However now in MX Xfce it finally looks like the mess for the users can come to an end, and I feel obligated to do my part to make it happen.
The script might help reveal the mess if it is there.
(Edit: a little spelling error corrected in the line above)

The script is in other ways a matter of taste. I like the slim version but maybe it can sometimes make sense also to log where the file showpath.sh actually was located when the "showpath.sh" command was executed, and "whereis" can do that.

Code: Select all

	#!/bin/bash
	echo "" >> ~/PATH_log.txt
	whereis "${0##*/}" >> ~/PATH_log.txt
	date +Kl-%R-%d-%b-%Y >> ~/PATH_log.txt
	echo $PATH >> ~/PATH_log.txt
	echo "" >> ~/PATH_log.txt
	featherpad + ~/PATH_log.txt
Last edited by Jakob77 on Thu Jun 12, 2025 3:22 pm, edited 1 time in total.

User avatar
Eadwine Rose
Administrator
Posts: 14622
Joined: Wed Jul 12, 2006 2:10 am

Re: A script to show PATH

#9 Post by Eadwine Rose »

If you want to make a difference you need to post this over at Debian themselves. THEY are the base of our distro after all.
MX-23.6_x64 July 31 2023 * 6.1.0-37amd64 ext4 Xfce 4.20.0 * 8-core AMD Ryzen 7 2700
Asus TUF B450-Plus Gaming UEFI * Asus GTX 1050 Ti Nvidia 535.247.01 * 2x16Gb DDR4 2666 Kingston HyperX Predator
Samsung 870EVO * Samsung S24D330 & P2250 * HP Envy 5030

User avatar
Melber
Developer
Posts: 1303
Joined: Tue Mar 23, 2021 4:19 pm

Re: A script to show PATH

#10 Post by Melber »

siamhie wrote: Wed Jun 11, 2025 7:51 pm How does it test the $PATH?
@siamhie was the question directed at me or the OP?

In both cases, neither "tests" PATH, we both just echo it, one into a pointless log file and the other into a pointless yad window. ;)

Post Reply

Return to “Scripts”