Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash脚本生成器_Bash_Shell - Fatal编程技术网

Bash脚本生成器

Bash脚本生成器,bash,shell,Bash,Shell,我试图通过从文件中读入并输出一个短语来生成侮辱生成器。文件(“myfile”有3列侮辱,我希望输出为“You Are a(侮辱1)(侮辱2)(侮辱3)” 到目前为止我所拥有的 while read line do Column1=$(cut -d" " -f 1) Column2=$(cut -d" " -f 2) Column3=$(cut -d" " -f 3) Insult1=${Column1[word]} Insult2=${Column2[word]} Insult3=

我试图通过从文件中读入并输出一个短语来生成侮辱生成器。文件(“myfile”有3列侮辱,我希望输出为“You Are a(侮辱1)(侮辱2)(侮辱3)”

到目前为止我所拥有的

while read line 
do

Column1=$(cut -d" " -f 1)    
Column2=$(cut -d" " -f 2)
Column3=$(cut -d" " -f 3)

Insult1=${Column1[word]}
Insult2=${Column2[word]}
Insult3=${Column3[word]}

echo "Thou art a" $Insult1 $Insult2 $Insult3
done < myfile
读取行时
做
第1列=$(切割-d”“-f 1)
第2列=$(切割-d”“-f 2)
第3列=$(切割-d”“-f 3)
侮辱1=${Column1[word]}
侮辱2=${Column2[word]}
侮辱3=${Column3[word]}
回应“你是一个”$侮辱1$侮辱2$侮辱3
完成

我对这一点非常了解,我只是在每个短语的开头没有“You Are a”,只有第一个。在到达字符串末尾之前,它会阅读所有的侮辱。

shell完全能够拆分空白输入。(让它不这样做可能是一个挑战!)


(这很有可能两次使用同一个形容词。如果你是一只脏狗,也许这根本不是问题。)

到目前为止,你所做的不是认真的尝试,是吗?它看起来有点像伪装的“请编写我的代码”.你现在可以看一看吗?我的文件有行尾吗?当你输入
head-1 myfile1
时,你会得到什么?只有第一行还是所有的侮辱?只有第一行“天真的基地苹果约翰”
while read first second third; do
    echo "Thou art a $first $second $third"
done <myfile
first=$(shuf -n 1 adjectives.txt)
second=$(shuf -n 1 adjectives.txt)
third=$(shuf -n 1 nouns.txt)
echo Thou art a $first $second $third