我正在创建一个 shellscript,它将打印出我们目录中的各种文件类型。它几乎可以工作,但是,由于某些奇怪的原因,当我尝试在我的输出中使用 uniq 时,它不起作用。这是我的输入(和 的值$FILE_TYPE)
POSIX shell script, ASCII text executable
ASCII text
Bourne-Again shell script, ASCII text executable
UTF-8 Unicode text, with overstriking
Bourne-Again shell script, ASCII text executable
Run Code Online (Sandbox Code Playgroud)
但是当我使用
FILE_TYPE_COUNT=`echo "$FILE_TYPE" | sort | uniq -c`
Run Code Online (Sandbox Code Playgroud)
这是它打印的结果
1 POSIX shell script, ASCII text executable
1 ASCII text
1 Bourne-Again shell script, ASCII text executable
1 UTF-8 Unicode text, with overstriking
1 Bourne-Again shell script, ASCII text executable
Run Code Online (Sandbox Code Playgroud)
显然应该是
1 POSIX shell script, ASCII text executable
1 …Run Code Online (Sandbox Code Playgroud)