我使用zsh和oh-my-zsh,并在我的~/中放入一个条目。zshrc为选项--dry-run=client -o yaml
提供快捷方式作为变量,并且可以更快地使用命令式命令生成yaml文件例如,当我输入kubectl run test-pod --image=nginx $do
时,我得到错误error: Invalid dry-run value (client -o yaml). Must be "none", "server", or "client".
,好像没有读取相等运算符。使用bash
可以正常工作我正在使用kubectl插件自动完成
我zshrc:
plugins=(git docker kubectl docker-compose ansible zsh-autosuggestions zsh-syntax-highlighting sudo terraform zsh-completions)
alias ls="exa --icons --group-directories-first"
alias ls -l="exa --icons --group-directories-first -lg"
alias ll="exa --icons --group-directories-first -lg"
alias cat="ccat --bg=dark -G Plaintext=brown -G Punctuation=white"
export PATH=$PATH:/usr/local/go/bin
# create yaml on-the-fly faster
export do='--dry-run=client -o yaml'
我bashrc: (
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
export do='--dry-run=client -o yaml'
,当我执行命令时,它工作正常
$ kubectl run test-pod --image=nginx $do
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: test-pod
name: test-pod
spec:
containers:
- image: nginx
name: test-pod
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
正如@Gairfowl提到的,区别在于zsh(默认情况下)不执行未加引号的参数展开的分词。
通过启用SH WORD SPLIT选项或在特定扩展上使用=标志,您可以启用"regular"分词和bash一样。为此,您需要遵循以下语法
kubectl run test-pod --image=nginx ${=do}
或
kubectl run test-pod --image=nginx ${do}
在情况下,如果这两个不工作尝试使用setopt
setopt SH_WORD_SPLIT
kubectl run test-pod --image=nginx $do
this ->Kubectl运行test-pod——image=nginx ${=do}并设置SH_WORD_SPLIT工作很好,谢谢你