タグ

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

  • Safer bash scripts with 'set -euxo pipefail' (Example)

    Preface: This article was originally posted here on my personal blog. Often times developers go about writing bash scripts the same as writing code in a higher-level language. This is a big mistake as higher-level languages offer safeguards that are not present in bash scripts by default. For example, a Ruby script will throw an error when trying to read from an uninitialized variable, whereas a b

    Safer bash scripts with 'set -euxo pipefail' (Example)
  • シェルスクリプトの罠を避ける三つの tips

    シェルスクリプトは、Unix 系環境で仕事をするエンジニアなら誰もが一度は書くであろうにもかかわらず、書き方や特性を熟知している人が少ない言語です。この記事は、シェルスクリプトを書くときに罠を踏まないようにするために最低限あなたが気を付けるべき tips 集です。「たかがシェルスクリプト」とは思わないでください。生半可に書かれたシェルスクリプトはあなたの (チームの) 生産性をかえって低下させます。 Shebang に bash を明示しろ Bash でしか使えない機能のことを俗に Bashism と言います。Bashism はもちろん Bash 以外のシェルでは動きません。これに関するありがちな罠は、以下のように発生します。 Bash が /bin/sh として使われている環境でシェルスクリプトを書く。うっかり Bashism がシェルスクリプトに含まれていても、 /bin/sh は何も

    シェルスクリプトの罠を避ける三つの tips
  • 上に行くcd作った - hitode909の日記

    シェルで,上のディレクトリに行くのがめんどくさくて,cd ../../../../とかしないといけなくて,指を痛める. 上に行くためのupっていうコマンドを作ることにした. その1 up 3ってやると,3つ上に行くのを作った. function up() { i=0 while [ $i -lt $1 ] do cd ../ i=`expr $i + 1` done } 使い方 % pwd /Users/fkd/co/dev/dotfiles % up 3 % pwd /Users/fkd %これは使いにくくて,cd ../../って打つときは,いくつ上に行くか考えながら,../って打ってる.これだと,先に数えておかないといけなくて,難しかった. その2 考えながら入力できるようにしてみた.引数の数だけ見る. function up() { i=0 while [ $i -lt $# ]

    a_bicky
    a_bicky 2013/12/31
    naoya さんのコメントがすごく参考になる(^ で cd ..)
  • ターミナルでのディレクトリ移動

    B! 7 0 0 0 ターミナルでのディレクトリ移動コマンドは最も良く使うコマンドだと思いますが、 良く使うコマンドだけに出来るだけ楽出来るようにしたいものです。 このページでは、数回前に居た時のディレクトリに戻りたい、 という時や、 複数のウィンドウで作業している時に、 一方のウィンドウで作業しているディレクトリに他方のウィンドウからも移動したい、 という時に簡単に移動出来るようなコマンドを紹介します。 cd pushd/popd cdをpushdのwrapperにする 異なるプロセス上でディレクトリ情報を共有する cd まずはcd(Change Directory)の簡単なまとめ。 1 2 3 cd directory # Go to directory cd # = cd ~, Go to $HOME cd - # Go to previous directory 通常、direct

    ターミナルでのディレクトリ移動
    a_bicky
    a_bicky 2013/12/31
    CDPATH とか pushd/popd のお話
  • UNIX コマンドの便利な利用方法 | Shinta's Site

    UNIX の書籍などでよく目にする、 'rn(1)' や 'ctime(3)' の括弧の中に書く数字にはどういう意味があるの? Cプログラム中で関数を使うときのような書き方ですが、これは、"UNIX manual" で、該当するドキュメントがある部分を 示すためにつけられた数字です。実際に 第3章にある "ctime" について の説明を読みたいときは、"man 3 ctime (Solarisでは、man -s 3 ctime)" と、man コマンドを実行することでドキュメントが参照できます。 伝統的なマニュアルは、このようなセクションに分かれています。

    a_bicky
    a_bicky 2012/01/05
    expectというのを使えば対話形式で入力を求められるコマンドも自動化できるとか
  • Explains: echo Command (echo $"string") Double-quoted String Preceded By a Dollar Sign - nixCraft

    echo $“Usage $prog start|stop|reload|restart” Why a double-quoted string preceded by a dollar sign ($”string”) using the echo command under Linux / UNIX bash scripts? Short answer – this is done to translate given string according to the current locale. More About Locale Your Linux script (or UNIX commands) may be used by all over the world in various languages other than English. Linux offers sup

    Explains: echo Command (echo $"string") Double-quoted String Preceded By a Dollar Sign - nixCraft
    a_bicky
    a_bicky 2011/09/24
    Shell Scriptで$"Hello"のような記述をするとPOTファイルから現在のlocaleに対応した翻訳結果をみつけて出力するっぽい
  • Why do shell script comparisons often use x$VAR = xyes?

    I see this often in the build scripts of projects that use autotools (autoconf, automake). When somebody wants to check the value of a shell variable, they frequently use this idiom: if test "x$SHELL_VAR" = "xyes"; then ... What is the advantage to this over simply checking the value like this: if test $SHELL_VAR = "yes"; then ... I figure there must be some reason that I see this so often, but I

    Why do shell script comparisons often use x$VAR = xyes?
    a_bicky
    a_bicky 2011/09/23
    "x$VAR" = "xyes"で比較する理由
  • KGussan Webpage

    フリーウェア [ScreenSaver] - 星雲紀行 - MLXS [Tools] - WPGen 曲 - 自作音楽 紹介等 - 自己紹介 - 寄付受付 - 音楽募集 - リンク集 - 注意・免責事項 - ライセンス - 著作権 グラフィックス - ジオメトリ - モデル - OFLライブラリ - モデリング - テクスチャ - テクスチャマッピング - 画像形式 Tech - memo 音楽 - 音楽 - DTM プログラミング [c] -- 最適化 - ライブラリ - DirectX - OpenGL -- 座標系 -- 行列演算 -- ツール - ODE - Windows [作法/スタイル] - 仕様書 - 作法 - Doxygen - Graphviz - UI - テスト - メンテナンス - Design Pattern [スクリプト] - ShellScript -- 文

    a_bicky
    a_bicky 2011/09/23
    Shell Scriptについてなかなかコンパクトにまとまっていて良い
  • Unixのコマンドラインで使えるちょっとした小技をまとめた『Unix Comman-Line Kung Fu』 | IDEA*IDEA

    ドットインストール代表のライフハックブログ

    Unixのコマンドラインで使えるちょっとした小技をまとめた『Unix Comman-Line Kung Fu』 | IDEA*IDEA
  • 変数を使用する | UNIX & Linux コマンド・シェルスクリプト リファレンス

    → 他のプログラミング言語と同様に = を使用する。 シェルスクリプトでも C言語などと同様に = を使用することで変数に値を設定することができる。ただし、C言語とは違い = の前後にスペースがあってはいけない。 また、変数名の大文字と小文字は区別されるため変数 VAR と変数 var は別物として扱われる。さらにシェル変数に「型」は存在しないので、文字列や数値を区別なく設定できる。 ポイントをまとめると以下のとおりとなる。 = を使う 値の設定時は変数名の先頭に $ を付けない ($ は参照時のみ) = の前後にスペースを入れない (前後にスペースがあるとエラー) 型は存在しない (declare コマンドや typeset コマンドで似たようなことができるが推奨はしない) 変数名の大文字・小文字は区別される (VAR と var は別物) 特に「2」は初心者が犯しがちなミスなので注意す

    変数を使用する | UNIX & Linux コマンド・シェルスクリプト リファレンス
    a_bicky
    a_bicky 2011/03/21
    環境変数 IFS は "Internal Field Separator" の略らしい
  • UNIX & Linux コマンド・シェルスクリプト リファレンス

    目次 当サイトについて bash シェルスクリプト入門 -シェルスクリプトのいろは- コマンド Tips シェルスクリプト Tips 変数を使用する 配列を使用する 入力と出力 if 文と test コマンド for 文の使用方法 while 文の使用方法 case 文の使用方法 関数の使用方法 引数を処理する 終了ステータス シグナルと trap コマンド フィルタを使用した文字列操作 1 フィルタを使用した文字列操作 2 日付を取得する 文字コードと改行コード シェルスクリプトのデバッグ AWK リファレンス (Deprecated) シェルスクリプト ライブラリ 『ether.sh』 お知らせ Bluesky を始めました @sunone.me 変更履歴 2023.10.07 ページ内リンクを修正した。 2021.02.01 このサイトに「もう 1 ページ追加しよう」と思ってから、も

    UNIX & Linux コマンド・シェルスクリプト リファレンス
  • UNIXシェルスクリプトメモ(Hishidama's UNIX shell script Memo)

    -xを付けると実行内容を表示しながら実行する。[2008-11-29] bash -x スクリプトファイル -nを付けると、実行せずにファイル内の構文解析(エラーの有無のチェック)を行う。[2008-11-29] bash -n スクリプトファイル . スクリプトファイル 現在実行中のシェルと同じシェルを使ってスクリプトを実行する。 スクリプトの中で環境変数を設定した場合、現在のシェルの環境にも影響する (スクリプトの中で定義した環境変数が実行元でも有効になる)。 ファイルに実行権限(chmod +x)が付いている場合は、以下のようにして実行できる(相対パスで指定している)。 ./スクリプトファイル ファイルに実行権限(chmod +x)が付いており、かつ環境変数PATHにカレントディレクトリ「.」が含まれている場合は、以下のようにして実行できる。 スクリプトファイル シェルスクリプトの書

  • UNIX Shell Quote

    Last modified: Fri Nov 27 09:44:59 2020 Written by Bruce Barnett Table of Contents Using the echo command Quoting a single character with the backslash Strong Quoting with the Single Quotes Weak Quotes with the Double Quotes Using quotes to include spaces and characters in filenames Quotes within Quotes Finding out if your quotes are wrong The verbose and echo variables in the C shell The Bourne S

    a_bicky
    a_bicky 2011/03/20
    Shellにおける引用符の使い方について
  • find/grep/xargsコマンドを使いこなす 業務で楽するためのUNIXテクニック集「検索」編

    CodeZine編集部では、現場で活躍するデベロッパーをスターにするためのカンファレンス「Developers Summit」や、エンジニアの生きざまをブーストするためのイベント「Developers Boost」など、さまざまなカンファレンスを企画・運営しています。

    find/grep/xargsコマンドを使いこなす 業務で楽するためのUNIXテクニック集「検索」編
    a_bicky
    a_bicky 2011/03/20
    想像以上に詳しく説明してた
  • Set Operations in the Unix Shell

    A while ago I wrote about how I solved the Google Treasure Hunt Puzzle #4 about prime numbers. I took an unusual approach and solved this problem entirely from the Unix shell. The solution involved finding the intersection between a bunch of files containing numbers. This lead me to an idea to write a post about how to do various set operations from the shell by using common utilities such as sort

    Set Operations in the Unix Shell
    a_bicky
    a_bicky 2011/03/14
    Shellで集合演算
  • 1