Is there a way to add an alias from the command line without directly editing the bash_aliases file? To clarify, how can I make a bash script do it without having to enter something along the lines of nano bash_aliases to add them?
How to add an alias without directly editing the `bash_aliases` file?
bash;alias;profile
Assuming you are using bash_aliases (it is not necessary, you can also have aliases defined in .bashrc among other places), you can simply add a line to the file:printf alias foo='bar' >> ~/.bash_aliasesAlternatively, if you only want this alias for the current session, use the alias command directly:alias foo='bar'ImportantBash does not allow aliases to be expanded (to work) in scripts by default, you will need to activate the expand_aliases option:#!/usr/bin/env bashalias foo='echo It works!'echo   Alias defined, attempting to use without expand_aliasesfooshopt -s expand_aliasesecho   Attempting to use with expand_aliasesfooIf I run the script above, the alias foo will only work after I have activated the expand_aliases option:$ a.sh  Alias defined, attempting to use without expand_aliases/home/terdon/scripts/a.sh: line 5: foo: command not found  Attempting to use with expand_aliasesIt works!