84669인 학습
152542인 학습
20005인 학습
5487인 학습
7821인 학습
359900인 학습
3350인 학습
180660인 학습
48569인 학습
18603인 학습
40936인 학습
1549인 학습
1183인 학습
32909인 학습
자동 스크립트를 작성하고 싶어요생성된 구성 파일을 먼저 테스트해보세요
테스트가 성공하면 nginx.conf를 덮어쓰세요. 실패하면 오류가 반환됩니다
그런데 테스트 지침을 실행한 후 정보를 어떻게 얻는지 모르겠습니다. 지침이 모두 성공적으로 실행되었습니다.
으아악
Bash에서는 이전 명령의 반환 값을 가져오는 데 $?를 사용합니다. 0은 정상이고 다른 값은 비정상입니다. $? 用来获取上一条命令的返回值,0 为正常,其他值为异常。
$?
如果需要获取命令输出,可以按一下方式操作:
[root@arbiter nginx]# /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful [root@arbiter nginx]# echo $? 0 [root@arbiter nginx]# /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/mime.types nginx: [emerg] "types" directive is not allowed here in /usr/local/nginx/conf/mime.types:2 nginx: configuration file /usr/local/nginx/conf/mime.types test failed [root@arbiter nginx]# echo $? 1
其中2>&1
2>&1
으아악
Bash에서는 이전 명령의 반환 값을 가져오는 데
$?
를 사용합니다. 0은 정상이고 다른 값은 비정상입니다.$?
用来获取上一条命令的返回值,0 为正常,其他值为异常。如果需要获取命令输出,可以按一下方式操作:
其中
명령 출력을 가져와야 하는 경우 다음과 같이 수행할 수 있습니다. 🎜 으아악 🎜2>&1
2>&1
의 기능은 표준 오류를 표준 출력으로 리디렉션하는 것입니다🎜