Shell

Bash

Bash

Export Variables From a File

If you store environment variables in a file and want to quickly export all of them it is actually not as simple as running an export on each line.

# source $MY_FILE
# export $(cut -d= -f1 $MY_FILE)

source

Another thing you can do is update ~/.bashrc or equivalent files for other shells and add a method to do this for you since those commands aren't easy to remember.

# ~/.bashrc
+ # exports variables stored in a file
+ function export_file() {
+   source $1
+   export $(cut -d= -f1 $1)
+ }

Fish

Fish

Add Custom User Path

You can use the set command to prepend a new path to your $PATH.

set -U fish_user_paths $HOME/.cargo/bin $fish_user_paths

`-U or --universal causes the specified shell variable to be given a universal scope. If this option is supplied, the variable will be shared between all the current user's fish instances on the current computer, and will be preserved across restarts of the shell.`