我正在尝试将eval "$(rbenv init -)"附加到我的bash配置文件中
(我正在尝试遵循此说明)
# Load rbenv automatically by appending
# the following to ~/.bash_profile:
eval "$(rbenv init -)"这是自动化过程的一部分,因此我无法访问GUI或无法使用编辑器。但是当我回显命令$(rbenv init -)时,它会被执行并附加一堆东西。如何将其作为纯文本回显?
这就是我现在拥有的
ec2-user@ip-172-31-46-129 ~ % cat /tmp/install-rbenv.sh
+-zsh:41> cat /tmp/install-rbenv.sh
#!/bin/bash
sudo -i -u buildkite-agent bash << EOF
echo "export RUBY_CONFIGURE_OPTS=\"--with-openssl-dir=$(brew --prefix openssl@1.1)\"" >> /Users/buildkite-agent/.bash_profile
echo 'eval "$(rbenv init -)"' >> /Users/buildkite-agent/.bash_profile
EOF
echo "Done"运行它
ec2-user@ip-172-31-46-129 ~ % . /tmp/install-rbenv.sh
+-zsh:42> . /tmp/install-rbenv.sh
+/tmp/install-rbenv.sh:6> brew --prefix openssl@1.1
+/tmp/install-rbenv.sh:6> rbenv init -
+/tmp/install-rbenv.sh:6> sudo -i -u buildkite-agent bash
+/tmp/install-rbenv.sh:10> echo Done
Done检查bash配置文件
ec2-user@ip-172-31-46-129 ~ % sudo su - buildkite-agent
+-zsh:43> sudo su - buildkite-agent
rbenv: no such command `sh-'
-bash: eval: line 31: syntax error near unexpected token `rehash'
-bash: eval: line 31: ` rehash|shell)'
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
ip-172-31-46-129:~ buildkite-agent$ cat ~/.bash_profile
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=/usr/local/opt/openssl@1.1"
eval "export PATH="/Users/ec2-user/.rbenv/shims:${PATH}"
export RBENV_SHELL=zsh
source /usr/local/Cellar/rbenv/1.1.2/libexec/../completions/rbenv.zsh
command rbenv rehash 2>/dev/null
rbenv() {
local command
command="${1:-}"
if [ "$#" -gt 0 ]; then
shift
fi
case "$command" in
rehash|shell)
eval "$(rbenv "sh-$command" "$@")";;
*)
command rbenv "$command" "$@";;
esac
}"发布于 2021-04-13 02:12:07
在第一个EOF前后使用撇号,即用'EOF'代替EOF。bash区分了这两种类型,如果您使用撇号版本,则不会计算内容。
> bash << EOF > test.sh
echo '$(date)'
EOF
> cat test.sh
Mon 12 Apr 2021 08:08:53 PM CEST> bash << 'EOF' > test.sh
echo '$(date)'
EOF
> cat test.sh
$(date)发布于 2021-04-13 01:44:48
显然你不想使用编辑器来编辑你的.bash_profile文件或者你的are afraid you will got trapped inside vi :-D
将想要附加到文件中的文本放在撇号中,它将逐字转到文件中。shell不会对包含在撇号中的参数进行任何扩展。
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile就这样。
https://stackoverflow.com/questions/67063036
复制相似问题