How to add export statement in a bash_profile file?
Simply write export AS='name'
anywhere in your ~/.bash_profile
file:
# Append to the end of the file
$ echo "export AS='name'" >> ~/.bash_profile
# Update shell
$ source ~/.bash_profile
This first command adds the line you want to the file (or just use a text editor) the second updates the shells with the new variable.
How to add export statements to bash_profile with Augeas and Puppet
This seems to do the trick:
augeas { "bash_profile-${user}-${name}":
incl => "/home/${user}/.bash_profile",
lens => 'Shellvars.lns',
changes => [
"set ${variable_name} '\"${literal_value}\"'",
"set ${variable_name}/export ''",
],
}
Exporting a filename in bash profile with a specific extension
"*" won't expand in variable creation process, try it like this:
SOS=$(ls "$anadir/$obsdir"/*SUM.ext)
[[ $SOS ]] && export SOS
Source a file and add export prefix in one go
This question was answered here: Set Environment variables from file
The second answer down has the method I would use.
export `sed -e '/^\#/d' -e '/^$/d' env.file1 | xargs`
That works fine for one file, but what about more than one, like in your question? May I submit this:
for ENV_FILE in env.*; do export `sed -e '/^\#/d' -e '/^$/d' "$ENV_FILE"; done
If you would like to only update those variables, without reloading bash altogether, I suggest making an alias for it. Then, just type the name of the alias and reload them any time you want.
Hope this helps.
export alias in ~.bash_profile for a path having a filename containing space
You have to quote the variable when you expand it:
sketch="/Users/amar/Library/Application Support/com.bohemiancoding.sketch3/Plugins"
cd "$sketch"
Quoting is not optional and there's nothing you can do to avoid it.
Do you need to include export for environment variables in bash profile / zshrc?
So is there a difference when prefixing the environment variable declaration with export inside the .zshrc file?
Yes, one is an environment variable and the other isn't.
The difference doesn't matter (much) to your shell, but to processes started by your shell. Environment variables are inherited by child processes, regular shell variables are not.
~ % foo=3; printenv foo
~ % export foo=3; printenv foo
3
In the first case, printenv
has no variable named foo
in its environment; in the second case, it does.
Related Topics
Crontab - Simple Echo Not Running
How to Use Systemd to Restart a Service When Down
Openssl/Rsa - Using a Public Key to Decrypt
How to Remove Special Characters in File Names
Embedding an Application (In This Case a Terminal) Within a Qt Application
Hidden File .Env Not Copied Using Docker Copy
Customize Tab Completion in Shell
Alternatives to Make for Linux/Freebsd
Bash Will Not Auto-Complete (Tab) with Files
How to Diagnose a Python Process Chewing CPU in Linux
Finding The Max and Min Values and Printing The Line from a File
Is Swarm Required for Using Multi-Host Networking Feature Using Overlay in Docker
Why Use G++ Instead of Gcc to Compile *.Cc Files
Time Waste of Execv() and Fork()
Can't Access Publicly Exposed Docker Container Port from External Machine, Only from Localhost