
そこに条件があるかもしれませんか/etc/rc.local
? Q&Aをたくさん見ましたが、ほとんど実行をお勧めしましたが、chmod +x
私の問題は異なります。実際にはする無条件に私のために動作しますが、そうでなければ動作しません。
#!/bin/sh
if [[ -e /usr/src/an-existing-file ]]
then
echo "seen" >> /etc/rclocalmadethis
fi
実行時に表示される奇妙なエラーは次のとおりですsystemctl status rc-local.service
。
rc.local[481]: /etc/rc.local: 3: /etc/rc.local: [[: not found
これは私とrc.local
同じ場所にありますls -lah /etc/
。
-rwxr-xr-x 1 root root 292 Sep 19 09:13 rc.local
私はDebian 10スタンダードエディションを使用しています。
答え1
この[[ ... ]]
構文はには無効です/bin/sh
。努力する:
if [ -e /usr/src/an-existing-file ]
then
echo "seen" >> /etc/rclocalmadethis
fi
/bin/sh -> /bin/bash
場合によっては、他のシェルがその構文をサポートしているため、機能することがありますが、ここには依存しません(ここに示すように)。
たとえば、ls -l /bin/sh
次を実行してこの情報を見つけることができます。
lrwxrwxrwx 1 root root 4 Jul 18 2019 /bin/sh -> dash
答え2
[[
Bash機能は利用できませんsh
:
root@d4b4b6325f2a:/# type [[
[[ is a shell keyword
root@d4b4b6325f2a:/# sh
# type [[
[[: not found
答え3
この場合、テストコマンドを見ることができます。
/usr/bin/test -e /usr/src/an-existing-file && /bin/echo "seen" >> /etc/rclocalmadethis