Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash Script to create another file

Tags:

bash

I created a simple shell script:

#!/bin/bash
clear
echo "Starting Script now....."
echo "Write the info below to a new file in same directory...."

echo "name: John Smith"
echo "email: [email protected]
echo "gender: M"
echo 
echo
echo "File is done"

I want to create a file in the same directory with the Name, email, and gender details. I don't want to do it from the command line like this:

#./script.sh > my.config

I'd rather do it from within the file itself.

like image 633
coffeemonitor Avatar asked Jun 26 '26 06:06

coffeemonitor


1 Answers

Heredoc.

cat > somefile << EOF
name: ...
 ...
EOF
like image 115
Ignacio Vazquez-Abrams Avatar answered Jun 28 '26 22:06

Ignacio Vazquez-Abrams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!