I am using Xilinx ISE, a program that requires to source a vendor script to setup the path for all its tools. Since this script breaks some functionalities of my shell I do not want to source it on the start of the shell but only when I need it.To do so I had setup an alias for source /long/path/to/script.For convenience I would like it if the tools provided by the program would just always work without the setup script. The Idea is to have aliases like the following for each of the n programs (for the sake of example lets assume they are named p1,...,pn)alias p1='source /long/path/;unalias p1;...;unalias pn;p1'Since there are many programs I want to ease the updating of the unalias chain.The Idea is to have alias iseRemoveSetup='unalias p1;...;pn'. To make the building of the aliases for the programs and iseRemoveSetup easier I defined a few functions. However if I call iseAddToRemoveCall from the alias command (here for analyzer) it does not have any effect. If I call it directly on the shell however it works fine.Below is the relevant part of my .bashrc:alias iseRemoveSetup=''function iseAddToRemove() {  alias iseRemoveSetup=`(alias iseRemoveSetup | cut -f2 -d ')`unalias $1;}function iseAddToRemoveCall() {  iseAddToRemove $1  echo iseRemoveSetup;$1}alias setupise='source /home/ted/Xilinx/tools/14.7/ISE_DS/settings64.sh'alias analyzer='setupise;'`iseAddToRemoveCall analyzer`I am aware that it would be an Idea to have a function like:function iseAlias() {  alias $1='setupise;'`iseAddToRemoveCall $1`}However I want to have the issue I described above fixed first. The issue becomes visible when I run type iseRemoveSetup, it outputs:iseRemoveSetup is aliased to `'
calling Bash Function from alias definition
bash;alias
The problem is that your alias definition (the one of iseRemoveSetup) is in a subshell:alias analyzer='setupise;'`iseAddToRemoveCall analyzer`For iseAddToRemoveCall analyzer a subshell is started and the alias definition affects only this subshell which is gone as soon as this line is done.This could be solved by changingalias analyzer='setupise;'`iseAddToRemoveCall analyzer`toalias analyzer='setupise;$(iseAddToRemoveCall analyzer)'and replacing echo iseRemoveSetup;$1 (in iseAddToRemoveCall) with echo unalias $1;$1. Thus the unalias would become part of the alias expansion and would be executed in the correct shell.alternativeAll this seems quite strange to me. Wouldn't it make more sense to start a subshell (type bash), run the setup, run the commands, and leave the subshell (^D) when finished?additional remarksman 1 bash:The first word of the replacement text is tested for aliases, but a word that is identical to an alias being expanded is not expanded a second time. This means that one may alias ls to ls -F, for instance, and bash does not try to recursively expand the replacement text.So you don't need unalias p1 in your alias definition before you call pi from it.It may be better to use an (associative) array with the commands you want to unalias and just work with the array.This is important, too, because you do exactly what you ought not to do:Bash always reads at least one complete line of input before executing any   of the commands on that line. Aliases are expanded when a command is read, not when it is executed. Therefore, an alias definition appearing on the same   line as another command does not take effect until the next line of input is read. The commands following the alias definition on that line are not   affected by the new alias. This behavior is also an issue when functions are executed. Aliases are expanded when a function definition is read, not when   the function is executed, because a function definition is itself a compound command. As a consequence, aliases defined in a function are not available   until after that function is executed. To be safe, always put alias definitions on a separate line, and do not use alias in compound commands.