文書の表示以前のリビジョンバックリンク文書の先頭へ この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。 ====== Bash(Bourne-Again Shell) ====== ===== シェバン(shebang) ===== bash を絶対パスを指定 <code bash> #!/bin/bash </code> env を使ってを指定 <code bash> #!/usr/bin/env bash </code> ===== source されたスクリプトのディレクトリパスの取得 ===== <code bash> script_dir=$(cd $(dirname ${BASH_SOURCE:-$0}); pwd) </code> source されていない場合は以下でも取得できる <code bash> script_dir=$(cd $(dirname $0); pwd) </code> ===== alias の設定方法 ===== .bashrc に以下のように設定する。<code> alias mysql='/usr/local/mysql/bin/mysql' alias mysqladmin='/usr/local/mysql/bin/mysqladmin' </code> 記述が反映することを確認する。<code> $ source .bashrc $ alias alias mysql='/usr/local/mysql/bin/mysql' alias mysqladmin='/usr/local/mysql/bin/mysqladmin' </code> ===== 端末起動時のプロンプト表示が遅い ===== pk-command-not-found で時間がかかって bash の起動に時間がかかる。\\ .bashrc に unset command_not_found_handle を追記する。 <code> $ vi ~/.bashrc </code> <code bash> # .bashrc # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi unset command_not_found_handle </code> ===== .bashrc をログイン時に自動で読み込ませる ===== .bash_profile に以下の記述を追加する。<code bash> if [ -f ~/.bashrc ]; then . ~/.bashrc fi </code> 変更を即時反映するには、以下のコマンドを実行する。<code> $ source .bash_profile </code> ===== 参考文献 ===== [[https://www.tohoho-web.com/ex/shell.html|]]\\ [[https://atmarkit.itmedia.co.jp/ait/spv/1811/21/news009.html|]]\\ [[https://ja.wikipedia.org/wiki/%E3%82%B7%E3%83%90%E3%83%B3_(Unix)|シバン(Unix)]]\\ [[http://qiita.com/yudoufu/items/48cb6fb71e5b498b2532 | bash/zshでsourceされたスクリプト内で、ファイル自身の絶対パスをとるシンプルな記法]]\\ [[http://luna2-linux.blogspot.jp/2011/03/fedora-14.html | Fedora 14 でコマンドを打ち間違えると・・・]]\\ [[https://blog.3qe.us/entry/2017/08/06/025159|bashの`export`の役割と`exec $SHELL -l`について補習する - Lambdaカクテル]]\\ [[https://shellscript.sunone.me/if_and_test.html|if 文と test コマンド | UNIX & Linux コマンド・シェルスクリプト リファレンス]]\\ [[https://shellscript.sunone.me/parameter.html|引数を処理する | UNIX & Linux コマンド・シェルスクリプト リファレンス]]\\ linux/bash.txt 最終更新: 2023/03/12 14:52by ともやん