Output the current PATH to text file using BASH script [closed]
I am trying to output the PATH used by the computer to a simple text file.
Something like echo PATH >PATH.TXT or >>PATH.TXT
With the double >>, it works but gives each on a different line and if I use the single of course it overwrites the previous line with the next. Using %~dpo >PATH.TXT, or %~fo >>PATH.TXT, or even %~nx0 >>PATH.TXT does not give me the output I want. Simply put I want to put the PATH into a text file for backup using a BATCH file incase I do something stupid like HELP PATH, which would change PATH completely.
Thanks in advance for any help.
bash
closed as off-topic by muru, Zanna, pa4080, Charles Green, d a i s y Dec 12 at 3:58
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – muru, Zanna, d a i s y
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I am trying to output the PATH used by the computer to a simple text file.
Something like echo PATH >PATH.TXT or >>PATH.TXT
With the double >>, it works but gives each on a different line and if I use the single of course it overwrites the previous line with the next. Using %~dpo >PATH.TXT, or %~fo >>PATH.TXT, or even %~nx0 >>PATH.TXT does not give me the output I want. Simply put I want to put the PATH into a text file for backup using a BATCH file incase I do something stupid like HELP PATH, which would change PATH completely.
Thanks in advance for any help.
bash
closed as off-topic by muru, Zanna, pa4080, Charles Green, d a i s y Dec 12 at 3:58
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – muru, Zanna, d a i s y
If this question can be reworded to fit the rules in the help center, please edit the question.
I'm not sure I understand the question correctly. Are you trying to echo the output of the current $PATH or working directory to a text file? If so then you are nearly there, from the command line you would doecho $PATH > file.txt
assuming you wanted to overwrite the contents of that file, use >> to append. Or do you want to find the current working directory of the script you are running? In other words when you execute you script are you looking to find the scripts current PATH or working directory from within the bash script?
– kingmilo
Dec 10 at 17:36
2
This is almost certainly a Windows' cmd.exe question.
– muru
Dec 11 at 1:35
add a comment |
I am trying to output the PATH used by the computer to a simple text file.
Something like echo PATH >PATH.TXT or >>PATH.TXT
With the double >>, it works but gives each on a different line and if I use the single of course it overwrites the previous line with the next. Using %~dpo >PATH.TXT, or %~fo >>PATH.TXT, or even %~nx0 >>PATH.TXT does not give me the output I want. Simply put I want to put the PATH into a text file for backup using a BATCH file incase I do something stupid like HELP PATH, which would change PATH completely.
Thanks in advance for any help.
bash
I am trying to output the PATH used by the computer to a simple text file.
Something like echo PATH >PATH.TXT or >>PATH.TXT
With the double >>, it works but gives each on a different line and if I use the single of course it overwrites the previous line with the next. Using %~dpo >PATH.TXT, or %~fo >>PATH.TXT, or even %~nx0 >>PATH.TXT does not give me the output I want. Simply put I want to put the PATH into a text file for backup using a BATCH file incase I do something stupid like HELP PATH, which would change PATH completely.
Thanks in advance for any help.
bash
bash
edited Dec 10 at 17:32
kingmilo
5,51111531
5,51111531
asked Dec 10 at 17:10
Asgi Wesa
83
83
closed as off-topic by muru, Zanna, pa4080, Charles Green, d a i s y Dec 12 at 3:58
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – muru, Zanna, d a i s y
If this question can be reworded to fit the rules in the help center, please edit the question.
closed as off-topic by muru, Zanna, pa4080, Charles Green, d a i s y Dec 12 at 3:58
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – muru, Zanna, d a i s y
If this question can be reworded to fit the rules in the help center, please edit the question.
I'm not sure I understand the question correctly. Are you trying to echo the output of the current $PATH or working directory to a text file? If so then you are nearly there, from the command line you would doecho $PATH > file.txt
assuming you wanted to overwrite the contents of that file, use >> to append. Or do you want to find the current working directory of the script you are running? In other words when you execute you script are you looking to find the scripts current PATH or working directory from within the bash script?
– kingmilo
Dec 10 at 17:36
2
This is almost certainly a Windows' cmd.exe question.
– muru
Dec 11 at 1:35
add a comment |
I'm not sure I understand the question correctly. Are you trying to echo the output of the current $PATH or working directory to a text file? If so then you are nearly there, from the command line you would doecho $PATH > file.txt
assuming you wanted to overwrite the contents of that file, use >> to append. Or do you want to find the current working directory of the script you are running? In other words when you execute you script are you looking to find the scripts current PATH or working directory from within the bash script?
– kingmilo
Dec 10 at 17:36
2
This is almost certainly a Windows' cmd.exe question.
– muru
Dec 11 at 1:35
I'm not sure I understand the question correctly. Are you trying to echo the output of the current $PATH or working directory to a text file? If so then you are nearly there, from the command line you would do
echo $PATH > file.txt
assuming you wanted to overwrite the contents of that file, use >> to append. Or do you want to find the current working directory of the script you are running? In other words when you execute you script are you looking to find the scripts current PATH or working directory from within the bash script?– kingmilo
Dec 10 at 17:36
I'm not sure I understand the question correctly. Are you trying to echo the output of the current $PATH or working directory to a text file? If so then you are nearly there, from the command line you would do
echo $PATH > file.txt
assuming you wanted to overwrite the contents of that file, use >> to append. Or do you want to find the current working directory of the script you are running? In other words when you execute you script are you looking to find the scripts current PATH or working directory from within the bash script?– kingmilo
Dec 10 at 17:36
2
2
This is almost certainly a Windows' cmd.exe question.
– muru
Dec 11 at 1:35
This is almost certainly a Windows' cmd.exe question.
– muru
Dec 11 at 1:35
add a comment |
2 Answers
2
active
oldest
votes
You change your PATH
with command:
PATH=/new-path:$PATH
For example here is how to correctly expand the PATH:
$ PATH=/newpath:$PATH
$ echo $PATH
/newpath:/home/rick/bin:/home/rick/.local/bin:/mnt/e/bin:/mnt/e/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
Here is just one way to break your PATH (by omitting $
prefix):
$ PATH=/brokenpath:PATH
$ echo $PATH
/brokenpath: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:
echo $PATH > PATH.TXT
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:
/home/rick/.profile:PATH="$HOME/bin:$HOME/.local/bin:$PATH"
/etc/profile.d/apps-bin-path.sh: export PATH=$PATH:${snap_bin_path}
/etc/profile.d/jdk.sh:export 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
/etc/environment:PATH="/mnt/e/bin:/mnt/e/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
add a comment |
You can print your PATH to a text file with the following code:
echo $PATH >> PATH.txt
If you want to run a file to do this, be sure to add a shebang to the top:
#!/bin/bash
echo $PATH >> PATH.txt
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You change your PATH
with command:
PATH=/new-path:$PATH
For example here is how to correctly expand the PATH:
$ PATH=/newpath:$PATH
$ echo $PATH
/newpath:/home/rick/bin:/home/rick/.local/bin:/mnt/e/bin:/mnt/e/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
Here is just one way to break your PATH (by omitting $
prefix):
$ PATH=/brokenpath:PATH
$ echo $PATH
/brokenpath: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:
echo $PATH > PATH.TXT
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:
/home/rick/.profile:PATH="$HOME/bin:$HOME/.local/bin:$PATH"
/etc/profile.d/apps-bin-path.sh: export PATH=$PATH:${snap_bin_path}
/etc/profile.d/jdk.sh:export 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
/etc/environment:PATH="/mnt/e/bin:/mnt/e/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
add a comment |
You change your PATH
with command:
PATH=/new-path:$PATH
For example here is how to correctly expand the PATH:
$ PATH=/newpath:$PATH
$ echo $PATH
/newpath:/home/rick/bin:/home/rick/.local/bin:/mnt/e/bin:/mnt/e/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
Here is just one way to break your PATH (by omitting $
prefix):
$ PATH=/brokenpath:PATH
$ echo $PATH
/brokenpath: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:
echo $PATH > PATH.TXT
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:
/home/rick/.profile:PATH="$HOME/bin:$HOME/.local/bin:$PATH"
/etc/profile.d/apps-bin-path.sh: export PATH=$PATH:${snap_bin_path}
/etc/profile.d/jdk.sh:export 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
/etc/environment:PATH="/mnt/e/bin:/mnt/e/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
add a comment |
You change your PATH
with command:
PATH=/new-path:$PATH
For example here is how to correctly expand the PATH:
$ PATH=/newpath:$PATH
$ echo $PATH
/newpath:/home/rick/bin:/home/rick/.local/bin:/mnt/e/bin:/mnt/e/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
Here is just one way to break your PATH (by omitting $
prefix):
$ PATH=/brokenpath:PATH
$ echo $PATH
/brokenpath: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:
echo $PATH > PATH.TXT
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:
/home/rick/.profile:PATH="$HOME/bin:$HOME/.local/bin:$PATH"
/etc/profile.d/apps-bin-path.sh: export PATH=$PATH:${snap_bin_path}
/etc/profile.d/jdk.sh:export 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
/etc/environment:PATH="/mnt/e/bin:/mnt/e/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
You change your PATH
with command:
PATH=/new-path:$PATH
For example here is how to correctly expand the PATH:
$ PATH=/newpath:$PATH
$ echo $PATH
/newpath:/home/rick/bin:/home/rick/.local/bin:/mnt/e/bin:/mnt/e/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
Here is just one way to break your PATH (by omitting $
prefix):
$ PATH=/brokenpath:PATH
$ echo $PATH
/brokenpath: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:
echo $PATH > PATH.TXT
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:
/home/rick/.profile:PATH="$HOME/bin:$HOME/.local/bin:$PATH"
/etc/profile.d/apps-bin-path.sh: export PATH=$PATH:${snap_bin_path}
/etc/profile.d/jdk.sh:export 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
/etc/environment:PATH="/mnt/e/bin:/mnt/e/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
edited Dec 10 at 18:18
answered Dec 10 at 18:12
WinEunuuchs2Unix
42k1070159
42k1070159
add a comment |
add a comment |
You can print your PATH to a text file with the following code:
echo $PATH >> PATH.txt
If you want to run a file to do this, be sure to add a shebang to the top:
#!/bin/bash
echo $PATH >> PATH.txt
add a comment |
You can print your PATH to a text file with the following code:
echo $PATH >> PATH.txt
If you want to run a file to do this, be sure to add a shebang to the top:
#!/bin/bash
echo $PATH >> PATH.txt
add a comment |
You can print your PATH to a text file with the following code:
echo $PATH >> PATH.txt
If you want to run a file to do this, be sure to add a shebang to the top:
#!/bin/bash
echo $PATH >> PATH.txt
You can print your PATH to a text file with the following code:
echo $PATH >> PATH.txt
If you want to run a file to do this, be sure to add a shebang to the top:
#!/bin/bash
echo $PATH >> PATH.txt
answered Dec 10 at 23:29
Gavin Morton
30111
30111
add a comment |
add a comment |
I'm not sure I understand the question correctly. Are you trying to echo the output of the current $PATH or working directory to a text file? If so then you are nearly there, from the command line you would do
echo $PATH > file.txt
assuming you wanted to overwrite the contents of that file, use >> to append. Or do you want to find the current working directory of the script you are running? In other words when you execute you script are you looking to find the scripts current PATH or working directory from within the bash script?– kingmilo
Dec 10 at 17:36
2
This is almost certainly a Windows' cmd.exe question.
– muru
Dec 11 at 1:35