The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

Views: 1,092β€…    Votes:  2β€…    βœ… Solution
Tag : bash  
Link: πŸ” See Original Answer on Ask Ubuntu πŸ”—

Title: Output the current PATH to text file using BASH script
ID: /2018/12/10/Output-the-current-PATH-to-text-file-using-BASH-script
Created: December 10, 2018    Edited:  December 10, 2018
Upload: November 24, 2022    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false

You change your PATH with command:


For example here is how to correctly expand the PATH:

$ PATH=/newpath:$PATH
$ echo $PATH

Here is just one way to break your PATH (by omitting $ prefix):

$ PATH=/brokenpath:PATH
$ echo $PATH

If you mess up your PATH usually you can simply close your terminal and reopen it.

Omitting the $ is the mistake made in your question as well. The method to capture PATH to text file is:


To keep a running log of PATH changes you can use:

echo $PATH >> PATH.TXT

PATH is an environmental variable. To set the variable we use β€œPATH=” but to reference it’s contents we need to use β€œ$PATH”.

The PATH variable can be set in many places as outlined in this Q&A: Where is my PATH variable being set?. To discover which files are setting the PATH one of the answers recommends using:

grep --color -H 'PATH=' ~/.bashrc ~/.profile ~/.bash_profile ~/bash.login \
                     ~/.bash_aliases /etc/bash.bashrc /etc/profile \
                     /etc/profile.d/* /etc/environment 2> /dev/null

On my machine the command returns:

/etc/profile.d/    export PATH=$PATH:${snap_bin_path}
/etc/profile.d/ PATH=$PATH:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
⇧ Purple theme for "Bash On Ubuntu On Windows" for Windows 10 ASUS PCE cant detect 5ghz network  β‡©