Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cat a file inside a shell function

Tags:

shell

I am wondering how I can implement something like the following:

test(){
  cat>file<<'EOF'
    abc
  EOF
}

Many thanks.

like image 672
Qiang Li Avatar asked Mar 24 '11 00:03

Qiang Li


People also ask

What is cat << EOF >>?

This operator stands for the end of the file. This means that wherever a compiler or an interpreter encounters this operator, it will receive an indication that the file it was reading has ended.

Can I use cat in a bash script?

The “cat” command in Bash stands for “concatenate”. This command is very frequently used for viewing, creating, and appending files in Linux. Today, we will explain to you the usage of this command in Bash in Linux Mint 20 by sharing some examples.

What does the cat command do in bash?

cat is one of the most frequently used commands in Unix operating systems. cat is used to read a file sequentially and print it to the standard output. The name comes from the way it can concatenates files.


1 Answers

Qiang:

Remove the spaces in front of EOF (so it's on a line by itself and not indented).

like image 149
Tyler A. Avatar answered Jan 01 '23 21:01

Tyler A.