bashの特異な書き方集
ファイル作成
touch の代わりに > を使用する。
$ cd lib && > my_gem.rb 標準出力に文字を渡す
echo の代わりに <<< を使用する。
$ cat <<< 'hi there' 理解できていない
subshellとして動かしたく無い場合にも使用するらしい。。。
$ read first second <<< "hello world" $ echo $second $first シーケンス
seq 1 2 10 の代わりに、 {1..10..2} を使用する。
#!/bin/bash echo "all odd numbers from 1 to 10 are" for i in {1..10..2} do echo $i; done macでは使用できない。
Bash Range: How to iterate over sequences generated on the shell – Linux Hint
This post is licensed under CC BY 4.0 by the author.