ExecStart에서 쉘 명령을 올바르게 이스케이프하는 방법은 무엇입니까?

ExecStart에서 쉘 명령을 올바르게 이스케이프하는 방법은 무엇입니까?

이것을 실행하세요:

[Unit]
Description=Save a screenshot
Wants=screenshot.timer

[Service]
Type=oneshot
ExecStart=/bin/sh -c 'DISPLAY=:0 scrot /home/myuser/Pictures/Journal/$(date +"%s").png'

[Install]

결과 :

scrot: Saving to file /home/myuser/Pictures/Journal//usr/bin/zsh.png failed: No such file or directory

왜? 셸에서 동일한 명령을 실행하면 정상적으로 작동합니다.

% /bin/sh -c 'DISPLAY=:0 scrot /home/myuser/Pictures/Journal/$(date +"%s").png'
% echo $?
0
% 

내가 사용하는 명령은 다음과 같습니다

systemctl --user daemon-reload && systemctl --user start screenshot.service; systemctl --user status screenshot.service

답변1

systemd 단위는 다음을 활용할 수 있습니다.다양한 "지정자"많은 영역 중에서 그 중 하나는 다음과 같습니다 %s.

지정자 중요성 세부 사항
%s 사용자 셸 서비스 관리자 인스턴스를 실행하는 사용자의 셸입니다.
%% 단일 퍼센트 기호 %%대신 %단일 백분율 기호를 지정 하는 데 사용합니다 .

%지정자에 의해 해석되는 필드의 systemd 단위에서 이를 사용해야 하는 경우 대신 사용하십시오 %%.

관련 정보