Page 1 of 2

A script to show PATH

Posted: Wed Jun 11, 2025 8:08 am
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

Re: A script to show PATH

Posted: Wed Jun 11, 2025 8:42 am
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.

Re: A script to show PATH

Posted: Wed Jun 11, 2025 1:50 pm
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. :-)

Re: A script to show PATH

Posted: Wed Jun 11, 2025 5:06 pm
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."

Re: A script to show PATH

Posted: Wed Jun 11, 2025 5:12 pm
by richb
Tone down commentary.

Re: A script to show PATH

Posted: Wed Jun 11, 2025 5:58 pm
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.

Re: A script to show PATH

Posted: Wed Jun 11, 2025 7:51 pm
by siamhie
How does it test the $PATH?

Re: A script to show PATH

Posted: Thu Jun 12, 2025 3:09 am
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

Re: A script to show PATH

Posted: Thu Jun 12, 2025 3:33 am
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.

Re: A script to show PATH

Posted: Thu Jun 12, 2025 8:28 am
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. ;)