为什么这个bash/shell脚本要从字符串中删除重复字符?

为什么这个bash/shell脚本要从字符串中删除重复字符?,bash,shell,Bash,Shell,我有一个脚本,它要求输入一个项目名,然后我想将该名称转换为一个安全的目录名。我正在使用以下命令: echo "Please enter the name of the new project (eg My New Project):" read -r project_name project_directory=$(echo "$project_name" | tr -s '[:upper:]' '[:lower:]' | tr -s '[:space:]') 我原以为这样做很好,但我今天注

我有一个脚本,它要求输入一个项目名,然后我想将该名称转换为一个安全的目录名。我正在使用以下命令:

echo "Please enter the name of the new project (eg My New Project):"
read -r project_name

project_directory=$(echo "$project_name" | tr -s '[:upper:]' '[:lower:]' | tr -s '[:space:]')
我原以为这样做很好,但我今天注意到,如果我输入一个包含2个或更多字符的单词,那么重复的字母也会被删除

Room = rom
Running = runing

只是有点困惑为什么,我的印象是脚本会将大写字符转换为小写,空格会被删除,但显然不会。有人能解释为什么吗?

因为这就是
tr-s
的作用。从手册页:

-s、 --重复挤压 将上一个指定集中列出的重复字符的每个序列替换为该字符的单个匹配项

如果您只想将其转换为上下,请删除
-s

tr '[:upper:]' '[:lower:]'