リファレンス
参考:
Bash Reference Manual (all in one page) | gnu.org
Bash Reference Manual (separate contents) | gnu.org
まとめ
参考:
文字列・配列・構文などの取り扱い方 | bioinformatics
UNIX & Linux コマンド・シェルスクリプト リファレンス | SUNONE
変数
参考:
Operations on variables | Bash Guide for Beginners (tldp.org)
case sensitive or not? – Stack Overflow
declare
参考:
declare コマンド – 変数を宣言する | Linux コマンド .NET
$@ と $* の違い
#! /usr/bin/env bash time "$@"
参考:
Bash $@ (Dollar At Variable) Loses Quote Characters | Biostar
What does “$@” mean in Bash? – Quora
変数名を取り出す
$ i_want_to_know_variable_name="hey!" $ echo "${!i_want_to_know_variable_name@}"
参考:
In bash, how can I echo the variable name, not the variable value? – Unix & Linux Stack Exchange
間接変数展開 (indirect variable expansion)
$ fire="red!" $ color="fire" $ echo "${!color}" red!
参考:
Bash expand variable in a variable – Stack Overflow
How to use call-by-reference on an argument in a bash function – Unix & Linux Stack Exchange
参照渡し (nameref)
local -n
コマンドで参照渡しの変数を定義する。外部の変数を書き換えられる。
$ function change () \ { \ local -n ref=$1; \ ref="bye"; \ } $ greeting="hello" $ echo $greeting hello $ change greeting $ echo $greeting bye
参考:
Shell Parameters | Bash Reference Manual (gnu.org)
The declare builtin command | Bash Hackers Wiki
Passing arguments by reference – Stack Overflow
Shell variables in a for loop – Unix & Linux Stack Exchange
間接参照
参考:
Indirect References | Advanced Bash-Scripting Guide (tldp.org)
クオォーテーションの違い
- Weak quoting:
"$var is replaced"
- Strong quoting:
'kind of $var is left as is'
- ANSI-C quoting:
$'kind of \e is replaced escape sequence'
- Locale Translation:
$"string can be localized"
参考:
Quotes and escaping | Bash Hackers Wiki
Quoting characters | Bash Guide for Beginners
ANSI-C Quoting | Bash Reference Manual (gnu.org)
Locale Translation | Bash Reference Manual (gnu.org)
ダブルクォーテーション
参考:
How to escape a double quote inside double quotes? – Stack Overflow
Why do we double-quote a dollar sign evaluation in Bash? – Unix & Linux Stack Exchange
ダブルクォーテーションとシングルクォーテーションの違い
参考:
ShellScript のダブルクォートとシングルクォートの違い – Qiita
ANSI-C クォーティング
参考:
ANSI-C Quoting | Bash Reference Manual (gnu.org)
How does the leading dollar sign affect single quotes in Bash? – Stack Overflow
How to escape quotes in shell? – Unix & Linux Stack Exchange
ロケールトランスレーション
参考:
Locale Translation | Bash Reference Manual (gnu.org)
What does it mean to have a $”dollarsign-prefixed string” in a script? – Unix & Linux Stack Exchange