gpt4 book ai didi

bash - 使用内容创建 shell 脚本

转载 作者:行者123 更新时间:2023-11-29 09:48:18 25 4
gpt4 key购买 nike

如何创建一个 shell 脚本来创建一个包含一大堆内容的文件。我目前有这个,但似乎效果不佳。也欢迎任何更清洁的方法。

echo "Enter 1 to generate View"
echo "Enter 2 to generate Model and View"
echo "Enter 3 to generate View, Model and Template"

while true; do
read -p "Please select an option: " option
read -p "Please enter the name of the class you wold like to genrate: " class
case $option in
1 )
FILE="views/$class"
/bin/cat <<EOM >$FILE
some content
EOM
break;;
2 )
exit;;
3 )
exit;;
* )
echo "Enter 1 to generate View"
echo "Enter 2 to generate Model and View"
echo "Enter 3 to generate View, Model and Template";;
esac
done

最佳答案

第二个EOM应该在一行的开头,或者使用

 # code
cat<<-EOM
...
EOM

所以在这里:

    /bin/cat <<EOM >$FILE
some content
EOM

注意:

喜欢barmar说,如果你使用 <<-EOM , 使用制表符而不是空格。

关于bash - 使用内容创建 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19756765/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com