LoginSignup
2
1

More than 5 years have passed since last update.

第 27 回シェル芸勉強会 参加しました

Posted at

とても勉強になって面白いことがいっぱいあったけど、特に印象に残ったことを覚え書き

  • 端末制御
    • stty 標準入力に紐付けられている端末の情報を得られる
    • tput 標準出力に紐付けられている端末の情報を得られる
  • 日常会話
    • ssh + tee テクニック cat ~/.ssh/authorized_keys | ssh <target_host> tee -a ~/.ssh/authorized_keys ssh でリモードコマンドを実行しようとすると、リダイレクトの扱いが面倒 (ローカルのシェルで解釈される) この時、tee が便利になる。また、目視できる。 ssh は標準入力をリモートコマンドの標準入力に流す機能がある。
  • sed こわい
    • ; で区切れる
    • パターンスペース、ホールドスペース
    • ストリームエディタ なので、範囲指定した操作も 1 行づつマッチして、操作を実行する seq 10 | sed '1,3d;2,5p の結果など
    • ラベル
    • sed での順次 ; 反復 :LABEL 分岐 b or t

sed でサクッと FizzBuzz 書いてしまえるあたりにシェル芸は愛せると再認識した。


:FIRST
/^)/b BRAC_STOP;
/^(/b BRAC_START;
/^./b SEQ;
b STOP;

:BRAC_START
x;
s/^/BRAC_START\n/;
x;
b SEQ;

:BRAC_STOP
x;
/^BRAC_START\n/b BRAC_ACCEPT;
s/^/BRAC_STOP\n/;
x;
b SEQ;

:BRAC_ACCEPT
s/^BRAC_START\n//;
x;
b SEQ;

:SEQ
s/^.//g;
b FIRST;

:ERROR
d;

:STOP
x;
/./b ERROR;
s/^/ACCEPT/;
p;
d;
2
1
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
2
1