Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a file by using cat in a bash script?

Tags:

linux

bash

How can I create a file by using cat in a bash script?

The commands below work fine through the shell, but not as a script:

cat > list.txt
Orange
Apple
Grape
Kiwi
Papaya
Banana
Strawberry
Blueberry
Peach
Pear
CTRL-D
like image 331
Kaguei Nakueka Avatar asked Oct 21 '25 05:10

Kaguei Nakueka


1 Answers

Use a here document within a script:

$ cat > list.txt <<EOF
Orange
Apple
Grape
Kiwi
Papaya
Banana
Strawberry
Blueberry
Peach
Pear
EOF
like image 144
Soren Avatar answered Oct 22 '25 18:10

Soren



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!