I want to have a script to call with params which adds some aliases to my current shell. The aliases have to be builded in respect to the calling parameters and the current directory from where I start it. If possible I would like to NOT have to source the script, just run it like any other script.
This is what I have done until now:
I wrote a small shell script to generate some aliases, like
echo 'alias foo="$1"'
and save it as file "myscript" with +x rights. Then I execute it via console to set the alias
$(myscipt hello)
that works fine
When I change my shell script like
echo 'alias foo="bar $1 -param"'
and execute again like above, the result is
bash: alias hello" not found
bash: alias -param" not found
???. I escaped already the blanks between bar and -param but can't get it work.
when I execute
source <(myscript hello)
everything is fine like expected (That is my solution by now but not sure if it is the best).
Some ideas how to get a better solution?
source
requires a file, which is what you get with process substitution<()
, but not with command substitution$()
. Your question however is a good example of an XY problem — usually it's better to ask about what you're in the first place trying to achieve rather than your attempted solution.$()
I do NOT source the result.$()
will inject the alias if there is NO space in the aliasing command. The question herefore is: What do I need to do if I want to use$()
and spaces to separate arguments? Whatever - maybe you have a good hint for me. Thanks.source <(myscript hello)
option not to your liking?