#!/bin/bash adj="$(shuf -n1 adjectives.txt)" noun="$(shuf -n1 nouns.txt)" echo ADJ $adj echo NOU $noun echo "$adj $noun"
ADJ humbler NOU lyric lyricr
或:
ADJ bipinnate NOU lipases lipasese
这种现象有一个腹水瘤: https://asciinema.org/a/199297
你的输入文件很可能有CRLF( \r\n \r (回车)将导致输出跳回当前行的第一列,因为您的连接摆脱了 \n 而不是 \右
\r\n
\r
\n
\右
这是Windows/DOS使用的格式。
您可以转换文件,也可以使用 tr ,例如:
tr
adj="$(shuf -n1 adjectives.txt | tr -d '\r')" noun="$(shuf -n1 nouns.txt | tr -d '\r')"
您也可以跨文件运行此操作,例如:
tr -d '\r' < adjectives.txt > adjectives-reformatted.txt