Page 1 of 1

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. ;)

Re: A script to show PATH

Posted: Thu Jun 12, 2025 10:26 am
by siamhie
Melber wrote: Thu Jun 12, 2025 8:28 am
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. ;)
Sorry @Melber, I should have quoted the OP when I made that comment.

Re: A script to show PATH

Posted: Thu Jun 12, 2025 3:36 pm
by Jakob77
siamhie wrote: Wed Jun 11, 2025 7:51 pm How does it test the $PATH?
There is an upgraded version in the first post now.
If you make that to a personal script, and if you name the script showpath.sh you can now use the Terminal command:

Code: Select all

showpath.sh --help
Does that help answering your good question.? :-)

Re: A script to show PATH

Posted: Thu Jun 12, 2025 4:54 pm
by siamhie
Jakob77 wrote: Thu Jun 12, 2025 3:36 pm
siamhie wrote: Wed Jun 11, 2025 7:51 pm How does it test the $PATH?
There is an upgraded version in the first post now.
If you make that to a personal script, and if you name the script showpath.sh you can now use the Terminal command:

Code: Select all

showpath.sh --help
Does that help answering your good question.? :-)

Not really because your initial post said this
for showing and testing PATH

I was wondering how the script tests the path. If it is just echoing for $PATH, then running that from a terminal is no different.

Code: Select all

╔═[siamhie@flux23]═[13:44 12/06/25]══════════════════════════════════════[~/.fluxbox]
╚═> echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/sbin:/usr/sbin
MX Fluxbox does come with a script folder that I can use for -my- personal scripts if I wanted to.

Code: Select all

╔═[siamhie@flux23]═[13:51 12/06/25]══════════════════════════════════════[~/.fluxbox]
╚═> ls -l --group-directories-first 
total 100
drwxr-xr-x  2 siamhie siamhie 12288 Apr 19 21:49 backgrounds
drwxr-xr-x 41 siamhie siamhie  4096 Jan 24 18:26 mystyles
drwxr-xr-x  2 siamhie siamhie  4096 Jan  1 12:40 scripts
drwxr-xr-x  7 siamhie siamhie  4096 Apr 29 08:32 styles
drwxr-xr-x  2 siamhie siamhie  4096 Jun 12 07:31 submenus
-rwxr-xr-x  1 siamhie siamhie  6073 Jun 12 13:42 apps
-rw-r--r--  1 siamhie siamhie    75 Mar 12 06:33 fbrun_history
-rw-r--r--  1 siamhie siamhie   291 Jan  1 07:54 fluxbox-mx-defaults
-rw-r--r--  1 siamhie siamhie  3689 Jun  2 08:15 init
-rw-r--r--  1 siamhie siamhie  4141 May 31 14:29 keys
-rw-r--r--  1 siamhie siamhie  5797 May 31 12:33 keys-BAK
-rw-r--r--  1 siamhie siamhie  3870 Jan 26 13:26 keys-orig
-rw-r--r--  1 siamhie siamhie   191 Sep 13  2024 lastwallpaper
-rw-r--r--  1 siamhie siamhie    66 Jan  1 07:54 menu
-rw-r--r--  1 siamhie siamhie  1089 May 10 17:00 menu-mx
-rw-r--r--  1 siamhie siamhie  1896 May 30 03:50 overlay
-rw-r--r--  1 siamhie siamhie    64 Jun 12 06:40 pre-global-menu.txt
-rw-r--r--  1 siamhie siamhie    12 Jun 12 13:19 slitlist
-rw-r--r--  1 siamhie siamhie  1962 May 28 07:26 startup
-rw-r--r--  1 siamhie siamhie   168 Jan  1 07:54 windowmenu

Re: A script to show PATH

Posted: Thu Jun 12, 2025 6:07 pm
by Jakob77
siamhie

There are many ways to test.
And the taste for remembering and typing a lot of Terminal commands can be very different.
However if you want to see how PATH looks when you run a personal user script I am afraid you will have to run a script.
I can not guide you about Fluxbox.

Re: A script to show PATH

Posted: Thu Jun 12, 2025 10:22 pm
by figueroa
Why not just:

Code: Select all

env | grep PATH
No script required.

Re: A script to show PATH

Posted: Fri Jun 13, 2025 3:09 am
by wdscharff
Why not just:
Too easy
Why simple when you can do it complicated?