if-then-fiをネスト[]に置き換えるには? ("[: -f: バイナリ演算子が必要です")

if-then-fiをネスト[]に置き換えるには? (

私の.bashrcファイルには次のものがあります。

if [ -f /etc/bash_completion ] && ! shopt -oq posix; then . /etc/bash_completion; fi

[]代わりに使用したいif then fi

私はすでにそれを持っています

[ -f ~/.bash_aliases ] && source ~/.bash_aliases
[ "${BASH_VERSINFO[0]}" -ge 4 ] && shopt -s autocd
[ -f ~/.git-completion.bash ] && source ~/.git-completion.bash

だから多分私は使用できると思いました。

[ [ -f /etc/bash_completion ] && [! shopt -oq posix] ] && . /etc/bash_completion

しかし、私は理解しています

-bash: [: -f: binary operator expected

ベストアンサー1

&&必要なく直接接続できます。条件は次のとおりです。

[ -f /etc/bash_completion ] && ! shopt -oq posix && . /etc/bash_completion

働く

おすすめ記事