1
0

More than 3 years have passed since last update.

ttl コマンド結果を変数(文字列)へ代入 整数値へ変換 if分岐 エスケープ

Last updated at Posted at 2019-09-21

●日本語訳
sendlnでdateコマンドを送信

recvlnでコマンドの実行結果をシステム変数(inputstr:文字列)へ代入

月の5日目までは先月のディレクトリ名で作成したいため、分岐用としてinputstrを整数値(dayint)へ変換する

ディレクトリを作成する

※注意点
sendlnでコマンドを送信する際、'(シングルクォート)や`(バッククォート)は16進数で変換しないと構文エラーとなってしまう。
'(シングルクォート) → #$27

`(バッククォート)  → #$60

;=======================================
;マクロ実行時の日付を変数 dayint へ代入する
;=======================================
sendln 'date +"%d"'
recvln                ; エコーバックを読み捨てる
recvln                ; 実行結果を取得

str2int dayint inputstr ; 分岐させるため日付の文字列を整数値へ変換する
wait '#'

If dayint < 5 then
    ;月の5日目までに実行する場合、先月のディレクトリを作成する
    sendln 'mkdir '#$60'date -d '#$27'1 month ago'#$27' +"%Y%m"'#$60
Else
    ;6日目以降の場合、当月のディレクトリを作成する
    sendln 'mkdir '#$60'date +"%Y%m"'#$60
EndIf
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0