How to create an alias that actually extends another alias of the same name inBash?Why:I used to have GREP_OPTIONS set on .bashrc to something like this:GREP_OPTIONS=-I --exclude=\*~I also had a script (let us say, setup-java.sh) which I would call beforeworking on some Java projects. It would contain the line:GREP_OPTIONS=$GREP_OPTIONS --exclude-dir=classesIf I also use Sass, then I would call setup-sass.sh which contains the line:GREP_OPTIONS=$GREP_OPTIONS --exclude-dir=\*/.sass-cacheBut GREP_OPTIONS wasdeprecated andapparently the standard solution is either create an alias or some script...
How to extend bash aliases
bash;grep;alias
Bash stores the values of aliases in an array calledBASH_ALIASES:$ alias foo=bar$ echo ${BASH_ALIASES[foo]}barWith parameterexpansionwe can get the either the last set alias (if exists) or the default value:alias grep=${BASH_ALIASES[grep]:-grep} -I --exclude=\*~Now just do it on setup-java.sh:alias grep=${BASH_ALIASES[grep]:-grep} -I --exclude=\*~  --exclude-dir=classes...and finally on setup-sass.sh:alias grep=${BASH_ALIASES[grep]:-grep} -I --exclude=\*~ --exclude-dir=\*/.sass-cacheIf the three lines are called, we get what we want:$ echo ${BASH_ALIASES[grep]:-grep}grep -I --exclude=\*~ -I --exclude=\*~ --exclude-dir=classes -I --exclude=\*~ --exclude-dir=\*/.sass-cache