タグ

tipsとshに関するcu39のブックマーク (3)

  • Help message for shell scripts

    July 7, 2020Have you ever thought how good it would be to have a help message for your shell script that you wrote a month ago and already forgot what it is supposed to do? Yeah, there is always a way to show a message using cat (meow) or a bunch of echo calls. But there is a neat trick. Add your message with all the required information on top of your file, just right after the shebang. #!/bin/ba

    Help message for shell scripts
    cu39
    cu39 2020/07/08
    スクリプト内にコメントでヘルプメッセージを書いておき、sedで該当コメント部分を加工して出力するhelp()を用意して、-hオプションがあったらそれを呼び出すという流れ。
  • How to check if a variable is set in Bash

    How do I know if a variable is set in Bash? For example, how do I check if the user gave the first parameter to a function? function a { # if $1 is set ? }

    How to check if a variable is set in Bash
    cu39
    cu39 2016/07/25
    unsetとset and emptyを区別する場合。
  • コンソールから切れたプロセスを標準出力につなげなおす - 絶品ゆどうふのタレ

    不慣れな環境を不意にいじった時にあるあるネタ。 とりあえずー とか言って勢いで書いたsetupスクリプトを実行してみたら意外と時間かかって、 ちょっと目を離した隙にsshの接続が切れちゃいました! 。。。ありますよね。ほんとよくありますよね。 そうなる予感はあったんだ なんて後の祭りです。ふとした油断から、screenもnohupすらも使わずにやってしまって、こんなことに。 shellがHUPしなかったからプロセスは生きてるものの、ログが見れないから進行状況がわからない。 うまく行ってるのかどうかモヤモヤした気持ちのまま、プロセスが終わるのをじっと待つ。。。 まぁ実に切ないです。 こんな時、いつも思うこと。 このプロセスの出力、もっかいstdoutに繋げられたらいいのに。。。 はい。というわけでつなげましょう。 長い前座ですみません。 切り離したプロセスを用意 #!/bin/bash wh

    コンソールから切れたプロセスを標準出力につなげなおす - 絶品ゆどうふのタレ
  • 1