Reputation: 5821
How does one create a shell script that creates a file with a whole bunch of contents. I currently have this and it does not seem to be working well. Any cleaner approach is also welcomed.
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
Upvotes: 2
Views: 3914
Reputation: 185171
The second EOM
should be at the beginning of a line, or use
# code
cat<<-EOM
...
EOM
So here :
/bin/cat <<EOM >$FILE
some content
EOM
Note :
like barmar said, if you use <<-EOM
, use tabs not spaces.
Upvotes: 4