![if-then-fi를 중첩[]으로 바꾸는 방법은 무엇입니까? ("[: -f: 이진 연산자가 필요합니다")](https://linux55.com/image/53395/if-then-fi%EB%A5%BC%20%EC%A4%91%EC%B2%A9%5B%5D%EC%9C%BC%EB%A1%9C%20%EB%B0%94%EA%BE%B8%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F%20(%22%5B%3A%20-f%3A%20%EC%9D%B4%EC%A7%84%20%EC%97%B0%EC%82%B0%EC%9E%90%EA%B0%80%20%ED%95%84%EC%9A%94%ED%95%A9%EB%8B%88%EB%8B%A4%22).png)
내 .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
일하다.
답변2
두 명령을 혼동하고 있습니다. 와 동일 하지 [
않습니다 if
.[
test
if
[[
단순한 명령이 아니라 제어 구조의 일부인 예약어(예: )입니다. if ... then ... else ... fi
거의 같다... && { ...; true; } || { ... }