BASHのエイリアスはバッシュ機能によって認識されていません:sunspot_rails、jruby、rspec
-
29-10-2019 - |
質問
以下のエイリアスバックグラウンドワークでサンスポットを実行するためのエイリアス以下のエイリアスを見つけて殺害するためのエイリアスは、Sunspotポートの動作変数をアクセスできますが、Sunspotを実行し、コマンドを処理し、殺害するための機能は、機能の外側で.bashrcを調達した後にのみです。 。
$ user_idは、このsunspot_ports()が呼び出され、最初にログインでログインすると適切に印刷される前に設定されます〜.bashrcのエイリアスです
私には開発と制作のエイリアスもあります - これは単なる代表的なコードです。
sunspot_ports ()
{
#alias sunspot_run_test to the user's port
sunspot_test_port=$(($user_id +5300))
echo "Your sunspot test port: $sunspot_test_port"
alias sunspot_run_test="RAILS_ENV=test sunspot-solr run -p${sunspot_test_port} &"
alias sunspot_kill_test="fuser -n tcp ${sunspot_test_port} -k"
export sunspot_production_port sunspot_development_port sunspot_test_port
}
solr_test()
{
#only makes the aliases be recognized when it is outside the function
#rebash
#aliases not recognized without a rebash prior to the function
sunspot_run_test
#commands not recognized even with rebash
#"RAILS_ENV=test sunspot-solr run -p${sunspot_test_port} &"
sleep 10;
"$@";
sunspot_kill_test;
#commands not recognized even with rebash
#"fuser -n tcp ${sunspot_test_port} -k"
}
関数内で.bashrcを調達し、エイリアスを拡張コマンドに置き換え、あらゆる組み合わせでsunspot_ports()の内側に関数を配置しようとしました。ログインすると、Sunspotポートが正しく印刷されるため、このコードが実行されることがわかります。
また、JVMにはフォーキングが許可されていないため、Jrubyコードのどこかではなく.bashrcの関数としてこれを使用する必要があります(そうでなければ、Sunspot-solr StartとSunspot-Solr Endを使用します。
解決
Bashは、呼び出された関数が最初に供給されている時点で既に定義されている場合にのみ、エイリアスを解決します。ただし、あなたの場合、エイリアスは関数で定義されます(sunspot_ports
)、そしてその機能は時によって実行されていません solr_test
調達されています。
いくつかのオプションがあります:
- 呼び出します
sunspot_ports
定義する前にsolr_test
- エイリアスを機能に置き換えます。
sunspot_kill_test() { user -n tcp ${sunspot_test_port} -k }
所属していません StackOverflow