견본:
[ctor@dom0 ~]$ cat nonsense
#!/bin/bash
set -vex
systemctl show "sys-devices-virtual-block-dm\x2d0.device"
echo
systemctl show sys-devices-virtual-block-dm\x2d0.device
echo
systemctl show 'random text here'.device
echo
\x2d
셸에서 해석되지 않으면 다음 출력은 괜찮습니다(인용되기 때문에).
[ctor@dom0 ~]$ ./nonsense
systemctl show "sys-devices-virtual-block-dm\x2d0.device"
+ systemctl show 'sys-devices-virtual-block-dm\x2d0.device'
SysFSPath=/sys/devices/virtual/block/dm-0
Id=sys-devices-virtual-block-dm\x5cx2d0.device
Names=sys-devices-virtual-block-dm\x5cx2d0.device
Wants=lvm2-pvscan@253:0.service
Description=/sys/devices/virtual/block/dm-0
LoadState=loaded
ActiveState=active
SubState=plugged
StateChangeTimestamp=Sun 2018-09-09 15:49:14 CEST
StateChangeTimestampMonotonic=10072227
InactiveExitTimestamp=Sun 2018-09-09 15:49:14 CEST
InactiveExitTimestampMonotonic=10072227
ActiveEnterTimestamp=Sun 2018-09-09 15:49:14 CEST
ActiveEnterTimestampMonotonic=10072227
ActiveExitTimestampMonotonic=0
InactiveEnterTimestampMonotonic=0
CanStart=no
CanStop=no
CanReload=no
CanIsolate=no
StopWhenUnneeded=no
RefuseManualStart=no
RefuseManualStop=no
AllowIsolate=no
DefaultDependencies=yes
OnFailureJobMode=replace
IgnoreOnIsolate=yes
NeedDaemonReload=no
JobTimeoutUSec=30s
JobTimeoutAction=none
ConditionResult=no
AssertResult=no
ConditionTimestampMonotonic=0
AssertTimestampMonotonic=0
Transient=no
StartLimitIntervalSec=10000000
StartLimitBurst=5
StartLimitAction=none
echo
+ echo
다음 출력은 sys-devices-virtual-block-dmx2d0.device
존재하지 않기 때문에 잘못된 출력입니다(셸에서 이를 제거하는 방법 참고 \
).
systemctl show sys-devices-virtual-block-dm\x2d0.device
+ systemctl show sys-devices-virtual-block-dmx2d0.device
Id=sys-devices-virtual-block-dmx2d0.device
Names=sys-devices-virtual-block-dmx2d0.device
Description=sys-devices-virtual-block-dmx2d0.device
LoadState=loaded
ActiveState=inactive
SubState=dead
StateChangeTimestampMonotonic=0
InactiveExitTimestampMonotonic=0
ActiveEnterTimestampMonotonic=0
ActiveExitTimestampMonotonic=0
InactiveEnterTimestampMonotonic=0
CanStart=no
CanStop=no
CanReload=no
CanIsolate=no
StopWhenUnneeded=no
RefuseManualStart=no
RefuseManualStop=no
AllowIsolate=no
DefaultDependencies=yes
OnFailureJobMode=replace
IgnoreOnIsolate=yes
NeedDaemonReload=no
JobTimeoutUSec=30s
JobTimeoutAction=none
ConditionResult=no
AssertResult=no
ConditionTimestampMonotonic=0
AssertTimestampMonotonic=0
Transient=no
StartLimitIntervalSec=10000000
StartLimitBurst=5
StartLimitAction=none
echo
+ echo
다음 출력은 random text here.device
존재하지 않기 때문에 잘못되었습니다.
systemctl show 'random text here'.device
+ systemctl show 'random text here.device'
Id=random\x5cx20text\x5cx20here.device
Names=random\x5cx20text\x5cx20here.device
Description=random\x5cx20text\x5cx20here.device
LoadState=loaded
ActiveState=inactive
SubState=dead
StateChangeTimestampMonotonic=0
InactiveExitTimestampMonotonic=0
ActiveEnterTimestampMonotonic=0
ActiveExitTimestampMonotonic=0
InactiveEnterTimestampMonotonic=0
CanStart=no
CanStop=no
CanReload=no
CanIsolate=no
StopWhenUnneeded=no
RefuseManualStart=no
RefuseManualStop=no
AllowIsolate=no
DefaultDependencies=yes
OnFailureJobMode=replace
IgnoreOnIsolate=yes
NeedDaemonReload=no
JobTimeoutUSec=30s
JobTimeoutAction=none
ConditionResult=no
AssertResult=no
ConditionTimestampMonotonic=0
AssertTimestampMonotonic=0
Transient=no
StartLimitIntervalSec=10000000
StartLimitBurst=5
StartLimitAction=none
echo
+ echo
따라서 존재하지 않는 위의 두 개는 .device
유사한 일반 출력을 표시하며 실제로 존재하지 않는다는 것을 나타내지 않습니다( Substate=dead
?). 장치 이름을 인용하는 것을 잊어버리기 쉽고 이것이 .device
보고 싶은 특정 장치에 대한 실제 정보라고 생각하는 실수를 범하지 않기 쉽습니다.
Qubes OS 4.0의 dom0에서 Fedora 25의 Systemd 버전 231 사용:
[ctor@dom0 ~]$ systemctl --version
systemd 231
+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN
systemctl에서 오류(및 종료 코드 != 0)가 발생하지 않는 이유는 무엇입니까?
답변1
이 show
명령은 동등한(그러나 인간을 위해 정의된) 명령을 사용하여 컴퓨터(사용자가 아님)가 구문 분석하도록 되어 있습니다 status
.
$ systemctl status 'random-text-here'.device; echo "Exit Status :$?"
● random-text-here.device
Loaded: loaded
Active: inactive (dead)
Exit Status :3