I have a directory say "/dir". Inside this directory I have files with the name arg1_config.tcl, arg2_config.tcl, arg3_config.tcl. There might be more files going forward with the same extension. I am trying to dynamically generate aliases for arg1, arg2 and arg3 in this case and below is my code for the same.
foreach i (`ls <path>/dir/*.tcl`)
set app = `echo $i | sed -e 's/.*\///g' | sed 's/_config.tcl//g'`
echo "app is $app"
alias $app 'run -app $app' # run is an internal script that takes arg1/2/3 as a switch
echo "alias $app 'run -app $app'"
end
When I source this file it prints
app is arg1
alias arg1 'run -app arg1'
app is arg2
alias arg2 'run -app arg2'
app is arg3
alias arg3 'run -app arg3'
However when I run which arg3 it says aliased to run -app $app and app value somehow is always the last value after exiting the foreach loop i.e arg3 in this case. I am not able to create aliases like the print messages above, i.e:
alias arg1 'run -app arg1'
alias arg2 'run -app arg2'
alias arg3 'run -app arg3'