이것은 무엇을 의미합니까? if [! -e "$exe"];

이것은 무엇을 의미합니까? if [! -e "$exe"];

나는 리눅스에서 스크립트를 보았다. 이것이 무엇을 의미하는지 알고 싶습니다.

if [ ! -e "$exe" ]; then
  exe='/path to some file'
fi

답변1

info test세부정보를 보려면 실행하세요 .

16.3.3 File characteristic tests
--------------------------------

These options test other file characteristics.

‘-e FILE’
     True if FILE exists.

‘-s FILE’
     True if FILE exists and has a size greater than zero.

‘FILE1 -nt FILE2’
     True if FILE1 is newer (according to modification date) than FILE2,
     or if FILE1 exists and FILE2 does not.

‘FILE1 -ot FILE2’
     True if FILE1 is older (according to modification date) than FILE2,
     or if FILE2 exists and FILE1 does not.

‘FILE1 -ef FILE2’
     True if FILE1 and FILE2 have the same device and inode numbers,
     i.e., if they are hard links to each other.

답변2

이는 "변수의 값이 exe파일 시스템의 기존 이름과 일치하지 않으면 해당 값을 /path to some file"로 설정하라는 의미입니다.

[ -e something ]테스트는 이름이 something일반 파일, 디렉터리 또는 기타 유형의 파일 이름으로 존재하는지 테스트합니다.

!테스트의 중요성을 부정합니다 .

if문은 주어진 명령(이 경우 명령은 [ ! -e "$exe" ])을 평가하고 명령이 성공하면(이 경우 파일은 실행됩니다)아니요존재하는 경우) 명령문 본문에 있는 명령문을 실행합니다 if(이 경우 변수에 대한 할당 exe).

[test유틸리티 설명서 ( man [또는 man test.

if명령문은 쉘 매뉴얼(예 man bash: )에 설명되어 있습니다. 매뉴얼에서는 변수와 변수 할당에 대해서도 설명합니다.

관련 정보