I want to run an alias inside a bash -c
construct.
The bash
manual says:
Aliases are not expanded when the shell is not interactive, unless the
expand_aliases
shell option is set usingshopt
In this example, why is the alias hi
not found when setting expand_aliases
explicitly?
% bash -O expand_aliases -c "alias hi='echo hello'; alias; shopt expand_aliases; hi"
alias hi='echo hello'
expand_aliases on
bash: hi: command not found
I'm running GNU bash, version 5.0.0(1)-release (x86_64-pc-linux-gnu)
.
Context: I want to be able to run an alias at idle priority, eg a script containing:
#!/bin/bash
exec chrt -i 0 nice -n 19 ionice -c 3 bash -c ". ~/.config/bash/aliases; shopt -s expand_aliases; $(shell-quote "$@")"
I want to avoid using bash -i
as I don't want my .bashrc
to be read.
bash -c "hi () { echo hello; }; hi"
outputshello
.zsh
: zsh aliases don't expand even with optioncomplete_aliases