タグ

shellscriptに関するtyruのブックマーク (38)

  • "trap ... INT TERM EXIT" really necessary?

    tyru
    tyru 2020/03/16
    "The POSIX spec doesn't say much about the conditions resulting in executing the EXIT trap, only about what its environment must look like when it is executed." うわー bash 以外だと trap ... EXIT だけじゃ実行されないケースが多いのか… (zsh, dash, busybox, ...)
  • bash によるオプション解析 - Qiita


       getoptgetoptsgetoptsgetopt   ============================= getopts getopt shift  getopt(3)  UNIX Cgetopt(1) Bourne 
    bash によるオプション解析 - Qiita
    tyru
    tyru 2017/02/11
    いつも自前処理してたけど getopts 使ってみた
  • 定期的にブラウザのタブを再読み込みしてスクリーンショットをSlackに投稿するシェルスクリプト - Qiita


    Linux Advent CalendarPiroJavaScriptRubyFirefoxLinux Linux Advent Calendar 
    定期的にブラウザのタブを再読み込みしてスクリーンショットをSlackに投稿するシェルスクリプト - Qiita
  • コマンドラインツールを書くなら知っておきたい Bash の 予約済み Exit Code - Qiita


    Exit Code 1, 2, 126165, 255 exit Exit Code 127 "command not found" exit1使Exit Code 1  Bash Exit Code /usr/include/sysexits.hC C++ 
    コマンドラインツールを書くなら知っておきたい Bash の 予約済み Exit Code - Qiita
    tyru
    tyru 2016/09/23
    exit code の推奨されてる使い方とかあるのか。
  • PIPESTATUSさようなら - Qiita


    Bash使PIPESTATUS POSIXUNIX 1) PIPESTATUS run() { local a j k l com # POSIX j=1 while eval "\${pipestatus_$j+:} false"; do unset pipestatus_$j j=$(($j+1)) done j=1 com= k=1 l= for a; do if [ "x$a
    PIPESTATUSさようなら - Qiita
  • Linuxに関わる人が一度は読むべきStackOverflowまとめ - Qiita


    StackOverflow Upvote/Downvote    StackOverflow   Font Size 10. Looping through the content of a file in Bash?  2015/10/23 : @heliac2000 @kawaz
    Linuxに関わる人が一度は読むべきStackOverflowまとめ - Qiita
    tyru
    tyru 2015/10/28
    readコマンドの落とし穴は勉強になった。コメント欄も合わせて。
  • GitHub - hannob/bashcheck: test script for shellshocker and related vulnerabilities

    You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert

    GitHub - hannob/bashcheck: test script for shellshocker and related vulnerabilities
  • Big Sky :: なんでもシェルで書いちゃう男の人って...。


    « C++  JSON  json11 initializer_list  | Main | 便 » ShellScript - jqxmllint - Qiita UNIX 1. 2.11  http://qiita.com/richmikan@github/items/e051b5d882c3dd2a39c6  UNIX  UNIX OS J
    Big Sky :: なんでもシェルで書いちゃう男の人って...。
  • 使いやすいシェルスクリプトを書く


    使  使使使usage usageusage使  function usage { cat <<EOF $(basename ${0})
    tyru
    tyru 2014/05/26
    自分の場合まず先頭に set -eu を書く。でも最近 set -e はいくらなんでも厳しすぎる気がしてきた… そこまでするなら普通にPythonとかで書いた方がいい。
  • source command not found in sh shell

    I have a script that uses sh shell. I get an error in the line that uses the source command. It seems source is not included in my sh shell. If I explicitly try to run source from shell I get: sh: 1: source: not found Should I somehow install "source"? Do I have a wrong version of sh?

    source command not found in sh shell
    tyru
    tyru 2014/05/08
    う、/bin/shにsourceコマンドなかったのか。後で . に置き換えよう。
  • システム統合にSOA? RDBMS? bashで十分! - @IT

    2009/09/07 毎年夏に開催される軽量プログラミング言語(LL:Lightweight Language)をテーマにした「LLイベント」。第7回目となる「LLTV」が、2009年8月29日に東京・中野で開催された。この記事ではプログラムの一部、「大改善!!劇的ビフォーアフター」をレポートする。前編では、Rubyによるfortuneコマンドの“増築”と、Firefox拡張によるslコマンドの実装というネタ系発表をレポートした。中編ではC言語にLisp風のマクロを取り入れ、lsコマンドのソースコードを約半分に削減する匠の技をレポートした。後編となる記事では、売り場業務が滞りがちだった販売管理システムをbashコマンドで“建て直した”という劇的ビフォーアフターの発表をレポートする。 DBを捨ててテキストファイルに変換 「100万件ぐらいの検索なら、シェルだけでも1000分の数秒でできます

    tyru
    tyru 2014/04/25
    これ同時アクセスしても大丈夫なの?と思ったけど複数アカウントでログインしないのかな。別店舗から同時アクセスする要求が出てきたらどうするんだろう。→ http://twitter.com/tyru/status/459711151257833472
  • Better Bash Scripting in 15 Minutes

    The tips and tricks below originally appeared as one of Google's "Testing on the Toilet" (TOTT) episodes. This is a revised and augmented version. Safer Scripting I start every bash script with the following prolog: #!/bin/bash set -o nounset set -o errexit This will take care of two very common errors: Referencing undefined variables (which default to "") Ignoring failing commands The two setting

    Better Bash Scripting in 15 Minutes
  • シェルスクリプトを書く時に気をつけている事など - Qiita

    あくまでも個人的な意見であって、自分がシェルスクリプトを書く時に気をつけている事を備忘録的に列挙しているだけです。 「こうするべきだ」と押しつけている訳ではありません。 勿論「私はこうしている」とか「こうすると良いよ」という意見や議論は大歓迎です。 export (1) しないシェル変数は全て小文字で書く。 PATH や HOME などは環境変数なので大文字で。 スクリプト内で使っているのは単なるシェル変数なので小文字で。 使い方をちゃんと区別する事は重要だと思う。 シェルの変数展開を活用しよう

    シェルスクリプトを書く時に気をつけている事など - Qiita
    tyru
    tyru 2013/04/03
    set今度から使おう
  • シェルスクリプトの[[と[の違い

    Yoshiaki Kawazu🐸ずん @kawaz シェルスクリプトのテストコマンド [ と [[ の違い。 [[はbashの組み込みコマンドで、[は単にtestという外部コマンドの別名。なので必然[[の方が速い。 [[では比較演算子の<と>がエスケープなしで使える。[では¥<や¥>とする必要がある。 (続く… 2013-02-12 14:05:41 Yoshiaki Kawazu🐸ずん @kawaz (続き) [[では比較演算子の<と>がロケールに応じた辞書順比較になる。[ではASCII辞書順。 [[では=~で正規表現マッチングが使える。bashバージョン3以降の機能。 [[では演算子を"-f"のようにクオートするとエラーになる。]では問題ない。 こんなところかな。 2013-02-12 14:07:56

    シェルスクリプトの[[と[の違い
    tyru
    tyru 2013/02/16
    めんどいのでいつも"["使ってる(そもそも/bin/bashに依存するシェルスクリプトを書くことになぜか敗北感を感じる変態なので)
  • 変数展開時の単語分割(word split)をマスターする - Qiita

    シェルスクリプトは、スペース区切りの文字列が代入された変数を展開するとき、文字列をスペースの位置で分割して複数の文字列のように扱う。この挙動は Bash (をはじめとする Bourne shell 系のシェル)と Zsh とで異なってくる。 普通の変数について Bash では、展開する変数をクォートしなければ単語分割が起きる。クォートすれば単語分割は起きず、スペースを含む1つの文字列として展開される。 Zsh では、変数をクォートするかしないかにかかわらず単語分割は起きない。ただし、 SH_WORD_SPLIT オプションをオンにすると Bash 準拠の挙動に変わる(デフォルトでオフ)。以下に単語分割の例を示す: ### 下準備 # 第1引数を echo する関数 function echo_first { echo $1 } # スペース区切りの文字列を含む変数 var="a b c"

    変数展開時の単語分割(word split)をマスターする - Qiita
  • Identifying and removing null characters in UNIX

    I have a text file containing unwanted null characters (ASCII NUL, \0). When I try to view it in vi I see ^@ symbols, interleaved in normal text. How can I: Identify which lines in the file contain null characters? I have tried grepping for \0 and \x0, but this did not work. Remove the null characters? Running strings on the file cleaned it up, but I'm just wondering if this is the best way?

    Identifying and removing null characters in UNIX
    tyru
    tyru 2012/08/21
    null byteを取り除くには tr -d '\000'
  • あなたの知らない>|と<>の使い方

    >や>>、>&といったひんぱんに使われるリダイレクトに対し、ほとんど使われることのないリダイレクトが>|と<>だ。実際には興味深い機能である、これら「知られざる」リダイレクトについて説明しよう。(編集部) あなたの知らないリダイレクト、>|と<> シェルが提供する機能はカーネルが提供している機能をダイレクトに利用するものが多い。つまり、シェルの記述がダイレクトにシステムコールに結び付くような機能が多いということだ。コマンドの実行、パイプ、リダイレクトなどは、そっくりそのままシステムコールに置き換わる。 リダイレクトであれば、ほとんどのケースで>ないしは>>で事足りるはずだ。2>&1という記述はこれで1つの機能に思えるが、これは>&というリダイレクトの典型的な使い方の1つであり、つまりはリダイレクトだ。 >、>>、>&はよく使われるリダイレクトといえる。しかし、sh(1)のマニュアルには次の

    あなたの知らない>|と<>の使い方
  • Functional programming in sh

    Warning: this code is horribly broken outside of use in Zsh. As such, all occurences of “sh” are referring to POSIX shells ie bash and /bin/sh, (which is usually symlinked to bash, minus some bash-only features). I find myself trying to do things I can do in GHCi more each passing day in my innocent /bin/sh. I find myself seeking a good balance between the numerous layers of hacks that compose she

  • How to Encrypt Your Bash Shell Script on Linux Using SHC

    Q: How do I encrypt my bash shell script on Linux environment? The shell script contains password, and I don’t want others who have execute access to view the shell script and get the password. Is there a way to encrypt my shell script? A: First, as a best practice you should not be encrypting your shell script. You should really document your shell script properly so that anybody who views it und

    tyru
    tyru 2012/06/02
    シェルスクリプト難読化ツール
  • bash: readとパイプと環境変数 | Webシステム開発/教育ソリューションのタイムインターメディア


     ( Bourne Shell )   ID ids  ID SHA1   (SHA1  shasum 使): cat ids | while read id do echo -n "$id" | shasum done | cut -d ' ' -f 1 >ids.sha1  read 使  sed  awk  
    bash: readとパイプと環境変数 | Webシステム開発/教育ソリューションのタイムインターメディア
    tyru
    tyru 2012/05/22
    これでひっかかって泣いてる