在Mac终端上为grep创建别名

时间:2017-05-14 23:51:55

标签: hash terminal grep alias

我通常运行此命令来验证文件的SHA1哈希值

shasum filename.txt |grep -E --color '<hash value>|$'

所以我为它创建了一个别名:

alias shacheck='check_sha_hash'

check_sha_hash() {
    shasum $1 |grep -E --color '$2|$'
}

但它没有帮助:

shacheck myfile.txt 3a5b106e413ab621ad13788e5ceab8ba1d974cb8
3a5b106e413ab621ad13788e5ceab8ba1d974cb8  myfile.txt --> didn't colorized the hash

我做错了什么?

1 个答案:

答案 0 :(得分:1)

尝试强制彩色输出,如下所示:

check_sha_hash() {
    shasum $1 | grep -E --color=always "$2|$"
}

有关详细信息,请参阅this question

相关问题