Variables, exports and aliases exist only in the shell where you made them. To keep them, put them in a file that bash runs each time it starts: ~/.bashrc.
This is one of the hidden settings files from "Hidden Files".
Add a line to ~/.bashrc
Use >> to add a line to the end. Or open the file in the editor.
learner@tidepool:~$ echo "alias errs='grep ERROR ~/logs/till.log'" >> ~/.bashrc
learner@tidepool:~$ echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc- Use
>>, not>. A>empties the file, and your other settings are lost. - The second line uses single quotes, so that
$HOMEand$PATHgo into the file as text. Bash puts in their values each time it reads the file.
source: use the changes now
Your shell started before you changed the file. source runs the lines of a file in the shell that you have now:
learner@tidepool:~$ source ~/.bashrc
learner@tidepool:~$ errs
09:20 ERROR drawer jammedbash ~/.bashrc does not work for this. It runs the file in a child process, and the child cannot change your shell.
~/.profile
~/.profile is a second settings file. It runs when you log in, not each time bash starts. On Ubuntu, it runs ~/.bashrc too. Put your aliases and exports in ~/.bashrc.