差分
このページの2つのバージョン間の差分を表示します。
次のリビジョン | 前のリビジョン | ||
linux:bash [2012/02/20 23:21] – 作成 ともやん | linux:bash [2023/03/12 14:52] (現在) – [参考文献] ともやん | ||
---|---|---|---|
行 1: | 行 1: | ||
====== Bash(Bourne-Again Shell) ====== | ====== Bash(Bourne-Again Shell) ====== | ||
+ | |||
+ | ===== シェバン(shebang) ===== | ||
+ | bash を絶対パスを指定 | ||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | </ | ||
+ | env を使ってを指定 | ||
+ | <code bash> | ||
+ | # | ||
+ | </ | ||
+ | ===== source されたスクリプトのディレクトリパスの取得 ===== | ||
+ | <code bash> | ||
+ | script_dir=$(cd $(dirname ${BASH_SOURCE: | ||
+ | </ | ||
+ | |||
+ | source されていない場合は以下でも取得できる | ||
+ | <code bash> | ||
+ | script_dir=$(cd $(dirname $0); pwd) | ||
+ | </ | ||
+ | |||
+ | ===== alias の設定方法 ===== | ||
+ | .bashrc に以下のように設定する。< | ||
+ | alias mysql='/ | ||
+ | alias mysqladmin='/ | ||
+ | </ | ||
+ | |||
+ | 記述が反映することを確認する。< | ||
+ | $ source .bashrc | ||
+ | $ alias | ||
+ | alias mysql='/ | ||
+ | alias mysqladmin='/ | ||
+ | </ | ||
+ | |||
+ | ===== 端末起動時のプロンプト表示が遅い ===== | ||
+ | pk-command-not-found で時間がかかって bash の起動に時間がかかる。\\ | ||
+ | .bashrc に unset command_not_found_handle を追記する。 | ||
+ | < | ||
+ | $ vi ~/.bashrc | ||
+ | </ | ||
+ | <code bash> | ||
+ | # .bashrc | ||
+ | |||
+ | # Source global definitions | ||
+ | if [ -f /etc/bashrc ]; then | ||
+ | . /etc/bashrc | ||
+ | fi | ||
+ | |||
+ | unset command_not_found_handle | ||
+ | |||
+ | </ | ||
===== .bashrc をログイン時に自動で読み込ませる ===== | ===== .bashrc をログイン時に自動で読み込ませる ===== | ||
- | .bash_profile に以下の記述を追加する。< | + | .bash_profile に以下の記述を追加する。< |
if [ -f ~/.bashrc ]; then | if [ -f ~/.bashrc ]; then | ||
. ~/.bashrc | . ~/.bashrc | ||
行 10: | 行 60: | ||
$ source .bash_profile | $ source .bash_profile | ||
</ | </ | ||
+ | |||
+ | ===== 参考文献 ===== | ||
+ | [[https:// | ||
+ | [[https:// | ||
+ | [[https:// | ||
+ | [[http:// | ||
+ | [[http:// | ||
+ | [[https:// | ||
+ | [[https:// | ||
+ | [[https:// | ||
+ |