0

All what I'm trying to do is to get VOL variable from /sound.cfg, depended by DEV number.

cat /sound.cfg
VOL1=20%

Systemd startup script includes:

[Service]
Environment="DEV=1"
EnvironmentFile=/sound.cfg
ExecStartPre=-/bin/bash -c "VOL=VOL${DEV} /bin/echo /usr/bin/amixer -c chan.${DEV} sset Mic ${!VOL} dev $DEV"

Unfortunately, echo shows me /usr/bin/amixer -c chan.1 sset Mic dev 1, without needed VOL1. Systemd doesn't support arrays, which would be very helpful.

asktyagi
  • 675
ZeLbeT
  • 1
  • You can't set a variable and use it in the same line. See https://unix.stackexchange.com/a/126947/70524 – muru May 31 '19 at 08:35
  • You have right. I've changed a few lines, but it doens't work also

    [Service] Environment="DEV=1" EnvironmentFile=/sound.cfg Environment="VOL=VOL${DEV}" ExecStartPre=-/bin/echo /usr/bin/amixer -c chan.${DEV} sset Mic ${!VOL} dev $DEV

    Still no VOL1 value.

    – ZeLbeT May 31 '19 at 08:51
  • Try ExecStartPre=-/bin/bash -c 'VOL=VOL$1 DEV=$2; /bin/echo /usr/bin/amixer -c chan.$DEV sset Mic ${!VOL} dev $DEV' _ ${VOL} ${DEV}. But you might better off putting the commands in a script. – muru May 31 '19 at 09:09
  • I tried, but without success. As you suggested - I've made an extra script which works as expected. Thank you for your help! – ZeLbeT May 31 '19 at 09:57
  • Since you want the shell to expand that variable, not systemd, use $${!VOL} ... – Murray Jensen Jun 01 '19 at 04:30
  • PS: put a semi colon after the setting of the variable e.g. VOL=VOL${DEV}; /bin/echo ... to avoid the problem mentioned by @muru – Murray Jensen Jun 04 '19 at 14:58

0 Answers0