我想在bash -c
构造中运行别名。
该bash
手册说:
当 shell 不是交互式时,别名不会被扩展,除非
expand_aliases
shell 选项是使用设置的shopt
在这个例子中,为什么显式hi
设置时找不到别名expand_aliases
?
% 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
Run Code Online (Sandbox Code Playgroud)
我在跑GNU bash, version 5.0.0(1)-release (x86_64-pc-linux-gnu)
。
上下文:我希望能够以空闲优先级运行别名,例如包含以下内容的脚本:
#!/bin/bash
exec chrt -i 0 nice -n 19 ionice -c 3 bash -c ". ~/.config/bash/aliases; shopt -s expand_aliases; $(shell-quote "$@")"
Run Code Online (Sandbox Code Playgroud)
我想避免使用,bash -i
因为我不想.bashrc
被阅读。