タグ

shellに関するhirose31のブックマーク (15)

  • Shell Style Guide

  • コマンド実行でシェルが怖いなら使わなければいいじゃない - 拡張 POSIX シェルスクリプト Advent Calendar 2013 - ダメ出し Blog

    http://blog.ohgaki.net/os-command-escape-shell-spec-command-implementation 「えすけーぷじゅうよう!!」を強調して言いたいからなのかシェルの理解が足りないからなのか、 意図がよくわからない文言やら説明が散見されますが、きりがないのでそれらはスルーします。 (シェルについては、なんで関係ない tcsh の話が出てくるんだとか、 位置パラメーター展開に $* 使うなとか、色々) 特に気になったのが以下の文章です。(強調は私によるもの) OSコマンドはOSが提供するシェルで実行されます。 シェルはテキストインターフェースを持ち、 テキストでコマンドとオプションを受け取り実行します。 例示した脆弱なPHPプログラムの場合、 ユーザーからの入力に対しセキュリティ処理を一切してないため、 簡単にサーバーを乗っ取られる可能性があり

  • ポータブルなシェルスクリプトを書く - 拡張 POSIX シェルスクリプト Advent Calendar 2013 - ダメ出し Blog

    拡張 POSIX シェルスクリプト Advent Calendar 2013、19日目の記事です。 うおー、あと 30分で書かないといけねー! 雑な内容ですみません。 今日はポータブルなシェルスクリプトの書き方ついてざっくり語ります。 UNIX 系 OS であれば大抵の OS / バージョンでも動くシェルスクリプト!! (ただし外部コマンドの非互換性の問題は除く) #!/bin/sh で書く POSIX sh でスクリプトを書けば完璧! shebang は #!/bin/sh!! …全然完璧ではありません。Solaris 10 のように /bin/sh が POSIX sh でない残念な OS がまだ生き残っています。 マニュアルにも載っているバグが仕様になったのではないかと思われる謎挙動や未知のバグを回避するのが大変です。 ポータブルにするには #!/bin/sh はまだ推奨できません。

    hirose31
    hirose31 2013/12/20
    checkbashisms知らんかった!!
  • test と [ と [[ コマンドの違い - 拡張 POSIX シェルスクリプト Advent Calendar 2013 - ダメ出し Blog

    test と [ と [[ コマンドの違い - 拡張 POSIX シェルスクリプト Advent Calendar 2013 - ダメ出し Blog 拡張 POSIX シェルスクリプト Advent Calendar 2013、15日目の記事です。 書くのが遅れ、ネタは尽きかけ、 マニアックさやニッチさが足りなくなってきているような気がします。 ふつうの内容ですみません。 今日は test, [, [[ コマンドの違いについてざっくり紹介します。 [[ がある bash, ksh, zsh ならば test と [ の使用は避け、 [[ を使用すべきです。 [ は慎重に使わないと様々な罠にかかるため危険です。 (翌日のネタも併わせてどうぞ) test と [ の違い どちらもシェルの組込みコマンドです。名前が違うのと [ は最後の引数を ] にしなければいけない縛りがある以外、 動作まった

  • 拡張 POSIX シェルスクリプト Advent Calendar 2013 - Adventar

    POSIX sh 以上の機能を備えた bash, ksh, zsh によるシェルスクリプトの話題。 なるべく外部コマンドに依存しないピュアシェルスクリプトを目指します。 sed, awk などのスクリプトが 80% 以上含むものはシェルスクリプトと認めません(老害)。…いや、嘘です、使います。 一人でやる予定だが未定。ネタください。

    拡張 POSIX シェルスクリプト Advent Calendar 2013 - Adventar
  • Shell Style Guide

    Revision 1.25 Paul Armstrong Too many more to mention Bash is the only shell scripting language permitted for executables. Executables must start with #!/bin/bash and a minimum number of flags. Use set to set shell options so that calling your script as bash <script_name> does not break its functionality. Restricting all executable shell scripts to bash gives us a consistent shell language that'

    hirose31
    hirose31 2013/10/28
    拡張子つけない、backticks使わない$(cmd)使う、数値計算とか文字列置換には組み込みコマンド使う、とか。V=; [ -n $V ] が真になるワナも[[なら大丈夫。
  • BashFAQ/050 - Greg's Wiki

    I'm trying to put a command in a variable, but the complex cases always fail! Variables hold data. Functions hold code. Don't put code inside variables! There are many situations in which people try to shove commands, or command arguments, into variables and then run them. Each case needs to be handled separately. For the simple case in bash, you can use an array to store arguments to pass to a co

    hirose31
    hirose31 2013/09/09
    スペース入りの引数の変数化した際のハンドリングとか
  • various system shells

    Bourne | Ash |  #! | find | ARG_MAX | Shells | whatshell | portability | permissions | UUOC | ancient | - | ../Various | HOME "$@" | echo/printf | set -e | test | tty defs | tty chars | $() vs ) | IFS | using siginfo | nanosleep | line charset | locale Various system shells 2001-09-04 .. 2023-08-14 (see recent changes) I created the list out of curiosity and from the viewpoint of history, portabil

    hirose31
    hirose31 2011/06/18
    /bin/sh
  • シェルスクリプトで乱数を扱う - hyconの日記

    シェル組込変数 RANDOM bashやzshなど一部のシェルでは特殊な変数 RANDOM があり、参照する毎に範囲の小さい整数を得ることが出来ます。 $ echo $RANDOM 30940 $ echo $((RANDOM % 100)) 22 jot(1) jot(1)は連番や乱数を出力するプログラムです。出力回数や範囲を指定出来るのでなかなか使い出はあります。deb系では athena-jot パッケージをインストールします。 $ jot -r 1 10 99 72 $ jot -r 10 1000 9999 8881 2834 3537 5889 7430 9962 4905 9548 3575 9762 awk awkの関数 rand() で0–1の範囲の実数の乱数を扱えます。srand() で乱数の初期化することを忘れずに。 $ awk 'BEGIN{srand();prin

    シェルスクリプトで乱数を扱う - hyconの日記
  • shell-fu

    Tip #892   Check memory and swap from command line Want to check the amount of used, free and total memory and swap from the command line? This script displays memory and swap information. Fully posix compliant and should work with all 2.[2-6].* kernels . Read more »

    hirose31
    hirose31 2008/04/23
    のTIPS集的な。よさげ。
  • シェルスクリプトで標準入力を加工する際の注意点 : DSAS開発者の部屋

    シェルスクリプトで標準入力を加工する際に若干ハマリかけたので、今回はそのお話をしたいと思います。 みなさんのシェルスクリプトライフの一助になれば幸いです。 標準入力を加工するシェル関数、例えば、 入力を文とするメールを送るシェル関数 ログを入力として受け取り、集計や解析をするシェル関数 を書く場合、みなさんどういう風に書いているでしょうか。 私は今までこんな風に書いていました… send_mail() { from='sender@example.org' to='receiver@example.org' { echo "From: ${from}" echo "To: ${to}" echo "Subject: test" echo cat - } | qmail-inject -A -f${from} } make_mail_body | send_mail これの何が問題かという

    シェルスクリプトで標準入力を加工する際の注意点 : DSAS開発者の部屋
  • どさにっき - 終わりのうしろ

    2007年2月21日(水) ■ anarchy golf _ というわけで、参戦してみた。いっさいズルはなし。 _ example_comでこれまでの記録を7バイト縮めてみた。\ もしかしたらあと数バイトほど小さくできるかもしれないけど、それを越えて小さくするには、圧縮済みデータを外部コマンド経由で展開するしか方法はないと思う。たぶん。 _ exit statusも、一時はいちばんだったんだけど、15分でズルに抜かれた。\ _ invert caseはズルなし gawk なしのものを考えてみたけど、66バイトがが限界。ズルなしでこれより30バイトも縮めるのは到底無理。\ _ 気がつくとあっというまに時間が過ぎてる。時間つぶしにはもってこいだが、やらなきゃいかん仕事があるときにやるもんじゃないな……。 2007年2月22日(木) ■ きょうのあなごる _ \ tennis - 6バイト減らし

    hirose31
    hirose31 2007/03/06
    exitの後にデータを書くの __DATA__ __END__
  • Advanced Bash-Scripting Guide

    This tutorial assumes no previous knowledge of scripting or programming, yet progresses rapidly toward an intermediate/advanced level of instruction . . . all the while sneaking in little nuggets of UNIX® wisdom and lore. It serves as a textbook, a manual for self-study, and as a reference and source of knowledge on shell scripting techniques. The exercises and heavily-commented examples invite ac

  • ShUnit

    Welcome! This is the premier (okay the only) unit testing framework for Bourne derived shells that I know about. Latest News Version 1.5 Released 2 Nov 2008 ShUnit returns an informative exit code for better integration in Continuous Integration tools. Version 1.4 Released 22 Mar 2008 ShUnit can detect test functions automatically. More News »

  • bash で,サブシェルが起動される条件 : DSAS開発者の部屋

    今回は少々マニアックというか,重箱の隅的お話です. bash(1) には,複数のコマンドをまとめたり,コマンドの実行結果をコマンドラインに取り込むための記法が複数あります.それらのコマンドを実行するために,bash は必要に応じてサブシェルを起動しますが,どういう記述をした際にサブシェルが起動されるのか,いまいちはっきりしなかったため,実際に試してみました.今回試したのは,( ), $( ), { }, <( ) です. を実行して,ps コマンドの親プロセスがどれになっているかで確認しています.bash が設定する $PPID 変数を見ないのは,変数の展開をどのシェルがするかに依存するために,確認しにくいからです.ps コマンドを --forest オプション付きで単純に起動すると $ ps --forest PID TTY TIME CMD 20218 pts/18 00:00:00

    bash で,サブシェルが起動される条件 : DSAS開発者の部屋
    hirose31
    hirose31 2006/09/13
    { }でもサブシェル起動されるんだぁ
  • 1