Kaguei Nakueka
Kaguei Nakueka

Reputation: 1108

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

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

Upvotes: 4

Views: 4990

Answers (1)

Soren
Soren

Reputation: 14688

Use a here document within a script:

$ cat > list.txt <<EOF
Orange
Apple
Grape
Kiwi
Papaya
Banana
Strawberry
Blueberry
Peach
Pear
EOF

Upvotes: 13

Related Questions