bash

bashでコマンド出力の各行を配列に設定する

bash4 以降は mapfile + プロセス置換を使う方法が標準的(?), スマートっぽい # git remoteを配列 remotes に設定する mapfile -t remotes < <(git remote) echo "${remotes[@]}"

PATHから特定のパスを抜く

echo "orig="$PATH IFS=':' read -a pathes <<< "$PATH" declare -a tmp_pathes for path in "${pathes[@]}" do if [ "$path" != "$HOME/.plenv/bin" ]; then tmp_pathes=("${tmp_pathes[@]}" "$path") fi done TMP_PATH=$(printf ":%s" "${tmp_pathes[@]}")…

bashビルトイン機能だけで headを実現する

% cat test 1 2 3 4 5 6 7 8 9 % echo "$(echo "$(