bash -c構成内でエイリアスを実行したい。
bashマニュアルには書かれています:
expand_aliasesシェルオプションが以下を使用して設定されていない限り、シェルがインタラクティブでない場合、エイリアスは展開されません。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
私は走ってい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 "$@")"
読まれbash -iたくないので使用は避けたい.bashrc。
bash -c "hi () { echo hello; }; hi"出力hello。