*通知*が*$shell()*の出力を解釈するようにします。

*通知*が*$shell()*の出力を解釈するようにします。

お知らせ(1)shell()次のように文書化された関数が提供されます。

   shell(s_cmd [,i_maxlen])
          Executes cmd as a system command, and returns the first 511
          characters  of  output resulting  from  cmd. Any  whitespace
          character in the output is converted to a space. Note that if
          RUN OFF has been executed, or the -r command-line option has
          been used, shell() will result in an error, and cmd will not be
          executed.

s_cmd標準出力に記録されているすべての項目を標準出力に記録したいです。思い出させるそれ自体。たとえば、

$ echo REM Sep 13 2018 MSG test >/tmp/test.rem
$ tail -2 ~/.reminders
SET tmp shell("cat /tmp/test.rem", -1)
$tmp

$tmp上記の行にコマンド出力を挿入しようとした失敗した試みはどこにありますか?実行するとrem(1)エラーは返されませんが、補間も行われません$tmp

$ rem
Reminders for Thursday, 13th September, 2018 (today):

$tmp 

$tmpこれは暗黙的な表現として解釈されると思いますREM …

INCLUDEこの場合、埋め込み出力を内部で生成する必要があるため、そのディレクティブは機能しません。)

ベストアンサー1

問題はshell()関数にあるのではありません

a) 式/変数方式を挿入します。[tmp]代わりに使用する必要があります。$tmp

b)in式はremind許可されていませんMSG

$ cat /tmp/foo.rem
SET var "REM Sep 13 2018 MSG test"
[var]
$ remind /tmp/foo.rem
/tmp/foo.rem(2): Can't nest MSG, MSF, RUN, etc. in expression
No reminders.

文書には次のように記載されています。

  o      You  cannot  use  expression-pasting to determine the type (MSG,
         CAL, etc.) of a REM command.  You can paste  expressions  before
         and  after  the  MSG, etc keywords, but cannot do something like
         this:
             REM ["12 Nov 1993 AT 13:05 " + "MSG" + " BOO!"]

ユーザーに警告するわけではありませんが、これが問題を解決するための最初の試みです。

SET tmp shell("cat /tmp/test.rem", -1)
REM [substr(tmp, 4, index(tmp, "MSG")-1)] MSG [substr(tmp, index(tmp, "MSG")+4)]

前提/tmp/test.remは形態がであるREM ... MSG ...

通知では、インデックスはゼロではなく1から始まります。

ノート

質問が実際に「通知ファイルに動的に生成されたコンテンツを含める方法」の場合は、シェルコマンドの出力を一時ファイルにリダイレクトしてから、そのファイルを含めてこれを達成できます。

INCLUDE [shell("echo REM " + today() + " MSG hello > /tmp/foo.rem; echo /tmp/foo.rem")]

あるいは、INCLUDE通常のファイルの代わりにfifoと一緒にこのコマンドを使用し、fifoが開くたびにスクリプトを使用してファイルに書き込むこともできます。

始める前にreminder:

$ mkfifo /tmp/remind-fifo
$ while echo 'REM Sep 18 2018 MSG test' > /tmp/remind-fifo; do sleep 1; done &

echoリマインダーコマンドを生成するために必要なスクリプト(たとえば)に置き換えられますsh my_script > /tmp/remind-fifo

その後、通知ファイルにfifoを簡単に含めることができます。

INCLUDE /tmp/remind-fifo

fifoメソッドは、インクルードメカニズム(C前処理器など)を持つ他のプログラムで使用できます。

おすすめ記事