シェルスクリプト総合 その33

■ このスレッドは過去ログ倉庫に格納されています
2020/03/23(月) 01:12:30.31ID:TYte82vJ
シェルスクリプトに関する総合スレッドです。

全般
・荒しは無視しましょう。
・丁寧な姿勢を心掛けましょう。
・ネチケット(死語)を意識しましょう。
・「○○(他の言語)でいいやん」は禁止。他のスレに行ってください。

シェルスクリプト総合 その32
https://mevius.5ch.net/test/read.cgi/tech/1571929725/
56デフォルトの名無しさん
垢版 |
2020/04/02(木) 14:38:12.64ID:BA8GpIv4
Windows 10, WSL, Ubuntu 18.04 に、Ruby のバージョンマネージャーのrbenv を、
rbenv-installer を使ってインストールしたのですが、
https://github.com/rbenv/rbenv-installer/blob/master/bin/rbenv-installer

これの34行目について、
rbenv="$(command -v rbenv ~/.rbenv/bin/rbenv | head -1)"

これを、bash スクリプト内に書いて、スクリプトを実行すると、
xxx="$(command -v rbenv)"

xxx は、~/.rbenv/bin/rbenv とパスが入り、

これを端末で直接実行すると、
xxx は、rbenv となって、パスが入らない!

bash スクリプト内に書いて、それを実行した時と、
端末に直接入力した時では、結果が異なってしまう!
2020/04/02(木) 14:41:15.78ID:o0fN+e0O
>>56
あのさ、シェルで変数Aに123って代入して
別のプログラム実行したら、変数Aに123が入ってなかった!
みたいな間抜けなレスは要らないから
2020/04/02(木) 19:04:30.73ID:mH0OQczo
>>56
command -V rbenv
type rbenv
してみ、端末で直接実行時に
最優先実行対象を返すんだからその結果で何もおかしなことはないよ
5956
垢版 |
2020/04/02(木) 21:38:05.69ID:BA8GpIv4
端末で、command -V rbenv, type rbenv を入力したら、
両方とも、rbenv という関数が表示された!

でも、 which rbenv と入力すると、
~/.rbenv/bin/rbenv と、ちゃんとパスが返ってくるけど

rbenv ()
{
local command;
command="${1:-}";
if [ "$#" -gt 0 ]; then
shift;
fi;
case "$command" in
rehash | shell)
eval "$(rbenv "sh-$command" "$@")"
;;
*)
command rbenv "$command" "$@"
;;
esac
}
2020/04/02(木) 22:11:52.53ID:mH0OQczo
which -- locate a program file in the user's path

command - execute a simple command
-v
Write a string to standard output that indicates the pathname or command that will be used by the shell, in the current shell execution environment (see Shell Execution Environment), to invoke command_name, but do not invoke command_name
以下省略するが読め
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html
■ このスレッドは過去ログ倉庫に格納されています
5ちゃんねるの広告が気に入らない場合は、こちらをクリックしてください。

ニューススポーツなんでも実況