How can I make export permanent? - windows

If I set a variable using export and then get out of the command line and go back to it, it no longer has that value. This is because export only works for subprocesses but not for parent processes. How can I get export to make the value permanent?

You can add the export in the file $HOME/.bash_profile and then run the following command:
source $HOME/.bash_profile

Related

Adding exports to ~/.bashrc

I'm working on installing the flow-project and I'm getting a message to add some things into my bashrc. Not sure if it matters but I'm on macOS.
This is the message it reads: https://i.stack.imgur.com/EbP3j.png
~/flow
Add the following to your ~/.bashrc:
export SUMO_HOME="$HOME/sumo_binaries/bin"
export PATH="$SUMO_HOME:$PATH"
I've looked in other threads too, I've added it manually as well as the "echo >> ~/.bashrc" method. It's definitely in the txt file. Thanks!
Edit: Question wasn't made clear, but I have tried putting the export ... into my .bashrc file but the thing I'm trying to install doesn't recognize that I've done that.
Verify what's exported with:
export -p
as per help
export: export [-nf] [name[=value] ...] or export -p
NAMEs are marked for automatic export to the environment of
subsequently executed commands. If the -f option is given,
the NAMEs refer to functions. If no NAMEs are given, or if `-p'
is given, a list of all names that are exported in this shell is
printed. An argument of `-n' says to remove the export property
from subsequent NAMEs. An argument of `--' disables further option
processing.

Why do my $PATH environment always reset after I open a new terminal on my mac?

Usually I will nano .zsh_profile
Then I will edit the path
#PYTHON
export PATH=/Users/ffff/Library/Python/3.8/bin:$PATH
# JAVA
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/bin:$PATH
#ANDROID
export ANDROID_HOME=/Users/ffff/Library/Android/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/tools/bin:$PATH
then I will save and exit
Then I will
source .zsh_profile
I will test the Java and ADB all is good, but one I open a new Terminal from my mac, it will say ADB and JAVA and Android_HOME not found
Why is it not persist? Did I miss out anything? My mac version is 12.2.1
The .zsh_profile file, has no special meaning. This is probably a confusion form Bash, where the bash_profile is executes for login shells. In Zsh, that equivalent would be ~/.zprofile. You might have some code in your .zshrc file, that overrides the PATH variable with something else. Because, as oppsed to .zprofile, the .zshrc file gets executed for every interactive non-login shells.
So my advice, checkout .zshrc and see if there's something overriding the PATH there, if so, maybe you want to change that, and NOT to execute these commands you want to add for every time a shell is opened, you should put them in .zprofile, so they only get executed once at login.

SH File not setting ENV variables (Mac OS X)

I have a file set_env.sh, that I run in the terminal using:
sh set_env.sh
The code runs, but the variables are not set. I am checking with
echo $EMAIL_SERVER
set_env.sh
#!/bin/sh
echo email Address
read y
echo email password?
read x
export EMAIL_SERVER='smtp.gmail.com'
export EMAIL_PORT=587
export EMAIL_DOMAIN='domain.com'
export EMAIL_AUTHENTICATION='plain'
export EMAIL_ENABLE_STARTTLS_AUTO=true
export EMAIL_USERNAME=$y
export EMAIL_PASSWORD=$x
Use source command instead:
source set_env.sh
The command executes the script in the current shell context as opposed to invocation via separate shell process: sh set_env.sh (the environment variables are set within the new sh process which is isolated from the current process).
By the way, you can use dot (.) instead of source, if you prefer.
You may modify your ~/.bash_profile file in your home dir with this
export EMAIL_SERVER='smtp.gmail.com'
export EMAIL_PORT=587
export EMAIL_DOMAIN='domain.com'
export EMAIL_AUTHENTICATION='plain'
export EMAIL_ENABLE_STARTTLS_AUTO=true
export EMAIL_USERNAME=$y
export EMAIL_PASSWORD=$x

Where is Shell Path in mac. .bash_profile Dont works correctly

When i use:
nano .bash_profile
the terminal show me:
export PATH=/usr/bin:/usr/sbin:/bin:/usr/local/bin:/sbin:/opt/x11/bin:$PATH
# Setting PATH for Python 3.4
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
export PATH
export PATH="/Applications/MAMP/Library/lib"
export PATH="/Applications/MAMP/Library/bin"
#XAMPP
#export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"
#export PATH="/Applications/XAMPP/xamppfiles/lib:$PATH"
But when i open a new terminal only shows. echo $PATH prints.
/Applications/MAMP/Library/bin
The problem is that when i execute a command the terminal returns :
command not found
I need to execute this command for the terminal to operate properly
export PATH=/usr/bin:/usr/sbin:/bin:/usr/local/bin:/sbin:/opt/x11/bin:$PATH
and echo $PATH prints.
/usr/bin:/usr/sbin:/bin:/usr/local/bin:/sbin:/opt/x11/bin:/Applications/MAMP/Library/bin
What can i do to open and edit the correct shell PATH ?
You are overiding your PATH variable every time you export. your .bash_profile should be
export PATH=/usr/bin:/usr/sbin:/bin:/usr/local/bin:/sbin:/opt/x11/bin
export PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
export PATH="/Applications/MAMP/Library/lib:$PATH"
export PATH="/Applications/MAMP/Library/bin:$PATH"
this way your current path is added to the end of the new path variable

Unable to open bash profile on OSX

I am unable to open bash profile. I had set the Java and Android path but suddenly it is opening. But when I run echo $PATH it is displaying the paths correctly. Now I need to add path to bash profile.
Could anyone please help me?
Your $PATH is wrong :
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin:/Users/qsgte‌​chnologies/Library/Android/sdk/platform-tools:/Users/qsgtechnologies/Library/Andr‌​oid/sdk/tools
This doesn't use standard default path, and, unless this is totally intentional, I recommend you not to do this.
You've got to fix it running this (note /bin:/usr/bin:):
export PATH=/bin:/usr/bin:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin:/Users/qsgte‌​chnologies/Library/Android/sdk/platform-tools:/Users/qsgtechnologies/Library/Andr‌​oid/sdk/tools:
The next time, be sure to use this syntax:
export PATH=$PATH/YourNewPath:
Since you removed /bin:/usr/bin: you where unable to change your bash profile because bash wasn't able to locate your executables.
Fitting your needs, here's your current bash_profile:
export JAVA_HOME=$(/usr/libexec/java_home)
export ANDROID_HOME=/Users/qsgtechnologies/Library/Android/sdk
export PATH=$JAVA_HOME/bin:/usr/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools
Change it to (note that YourNewEntry is a placeholder for the value you need)
export JAVA_HOME=$(/usr/libexec/java_home)
export ANDROID_HOME=/Users/qsgtechnologies/Library/Android/sdk
export PATH=$JAVA_HOME/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:/YourNewEntry
Then apply your changes:
source ~/.bash_profile

Resources