macとlinuxでコマンドが微妙に違うので煩わしい時の設定
macとlinuxに入ってるawkやらsedは別物です。 BSDライセンスやらGPLライセンスの関係があるらしいです。 (Appleが公式には言及してないとのこと) ただしこれはプリインストールされているawkやらsedがbsdってだけで別途インストールすればgnu版も使えます。 coreutils(lsとかlinuxでの基本コマンド)とかも入ってないですがその辺は基本オプション的には一緒なので入れてないです。
$ brew install gawk $ brew install gnu-sed $ brew install gnu-tar
中身を見てみると
brew info gawk gawk: stable 5.0.1 (bottled) GNU awk utility https://www.gnu.org/software/gawk/ /usr/local/Cellar/gawk/5.0.1 (90 files, 4.7MB) * Poured from bottle on 2019-11-09 at 13:14:35 From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/gawk.rb ==> Dependencies Required: gettext ✔, mpfr ✔, readline ✔ ==> Analytics install: 7,148 (30 days), 21,353 (90 days), 120,559 (365 days) install_on_request: 5,842 (30 days), 17,175 (90 days), 93,009 (365 days) build_error: 0 (30 days) gawk --version zsh: correct 'gawk' to 'awk' [nyae]? n GNU Awk 5.0.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.1.2) Copyright (C) 1989, 1991-2019 Free Software Foundation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
gnuから取ってきてるのがわかりますね。
あとは適当にawkやらsedにaliasを貼っておけばmac上で書いたワンライナーがそのままlinuxへ流用できるようになります。 (下のような感じ)
ちなみに
macOS Catalinaからzshがデフォルトになってbashがプリインストールされなくなりました。 これについてもbashのライセンスがmac的によろしくなくなってしまったという噂もあります。 (もちろんappleはそんな言及はしてないのであくまでも噂レベル)
個人的には自分が管理してないマシンは99.999%でbashオンリーなのでmacにあったほうがいいなと思うので残しておいて欲しかった感。 もちろんbrewで入れれるしソースからコンパイルして最近出たbash5.0だかも入れれるので問題はないですが。