How to Add Export Statement in a Bash_Profile File

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



Leave a reply



Submit