4

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

1 Answer 1

13

Use a here document within a script:

$ cat > list.txt <<EOF
Orange
Apple
Grape
Kiwi
Papaya
Banana
Strawberry
Blueberry
Peach
Pear
EOF
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.