タグ

!tumblr-techとshellscriptに関するtyruのブックマーク (4)

  • パイプでつないだコマンドの終了ステータスをとる

    cles::blog 平常心是道 blogs: cles::blog NP_cles() « コピペだけでレポートを作らせる :: AWS が Memcached 互換の Amazon ElastiCache をリ... » 2011/08/24 パイプでつないだコマンドの終了ステータスをとる  sh 49 1へぇ パイプでつないだコマンドの終了ステータスをとる方法が分かったのでメモ。 普通はあまり使わないテクニックですが、シェルスクリプトを組むときにパイプの前半部分の終了コードが必要になることがあります。 $ hogecmd | tee -a hoge.txt 例えば上記のようなコマンドの直後に$?で終了ステータスを取得すると、hogecmd ではなく、tee -a hoge.txt の部分の終了ステータスになってしまって、シェルスクリプトで条件分岐を書くときに困るのです。この制約を突破

    パイプでつないだコマンドの終了ステータスをとる
  • mkdir & cd into it as single command Using cd, mkdir

    How often do you make a directory (or series of directories) and then change into it to do whatever? 99% of the time that is what I do. This BASH function 'md' will make the directory path then immediately change to the new directory. By using the 'mkdir -p' switch, the intermediate directories are created as well if they do not exist. Show Sample Output

  • findとgrepの合わせ技 - Plan9日記

    カーネルなど大規模なソースコードを検索したい場合、findとgrepを使ったり、タグジャンプを使うだろう。Eclipse使う場合とか異論はあると思うけど、今日はfindとgrepの合わせ技について調べてみた。 普段はxargsを噛ませて、 $ find . -name \*.c | xargs grep hogehogeとかやるんだけど、findの-execオプションを使った場合とどれくらい性能差があるのだろうか? 評価環境はVMWare Fusion上のUbuntu 11.04。Linux kernel 2.6.28.10のfs以下で、まずは次の3パターンを比較してみた。3回測定してtimeの最良値を示す。おそらく対象ファイルはファイルキャッシュに載っている思う。 $ time find . -name \*.c -exec grep wait_event_interruptible {

    findとgrepの合わせ技 - Plan9日記
    tyru
    tyru 2011/05/08
    つい-exec使っちゃうな。意味が変わらん場合はxargs使おう
  • Shellのシングルクォート - てきとうなメモ

    Shellのシングルクォートはエスケープしないのでシングルクォートの中でシングルクォートを利用することができない。 Enclosing characters in single-quotes ( '' ) shall preserve the literal value of each character within the single-quotes. A single-quote cannot occur within single-quotes. Shell Command Language 例えば以下は内部のシングルクォートはエスケープされておらずシングルクォートを一旦とじてまた開いた状態になっている $ echo 'That\'s right' >以下のようにすれば意図通りに出力できるんだけどもめんどい $ echo 'That'\''s right' That's right

    Shellのシングルクォート - てきとうなメモ
  • 1