PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, October 29, 2022

[FIXED] How can I read a file in cat << EOF >

 October 29, 2022     cat, eof, linux, shell     No comments   

Issue

I would like to print a file in cat << EOF>. e.g.

$cat file
ad3
c43
34e
se3
we3

My script is:

$cat run.sh
cat << EOF > test.sh
#!/bin/bash
some commands
cat file #I would like to print the content of the file here
some commands
EOF

I can't able to print as desire with ./run.sh

Desire output

$cat test.sh
#!/bin/bash
some commands
ad3
c43
34e
se3
we3
some commands

Solution

You could use backticks, or write the file in chunks:


#!/bin/bash

cat <<OMG >zfile
ad3
c43
34e
se3
we3
OMG

# Method1 : backticks

cat << EOF > test.sh
#!/bin/bash
some commands1
`cat zfile`
some commands2
EOF

# Method2: append

cat << EOF1 > test2.sh
#!/bin/bash
some commands1
EOF1

cat zfile >> test2.sh

cat << EOF2 >> test2.sh
some commands2
EOF2


Answered By - wildplasser
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing