F
F
fokin_nikolay19892021-10-28 22:18:04
linux
fokin_nikolay1989, 2021-10-28 22:18:04

How to write multiple lines to a bash file?

Tell me how you can write multiple lines to a file through the command line?
Example:

echo “
«Строка 1
Строка 2
Строка3» >> /home/2.txt

Each line with a new line
Maybe echo should not be used

Answer the question

In order to leave comments, you need to log in

5 answer(s)
R
Ronald McDonald, 2021-10-28
@Zoominger

cat << EOF > your_file.txt
str1
str2
str3
EOF

Oh, well, you can echo:
echo "str1
str2
str3" >> myfile.txt

A
Alexander Karabanov, 2021-10-29
@karabanov

cat > /etc/sysconfig/network-scripts/ifcfg-"${nameINT}" <<EOF
NAME="${nameINT}"
DEVICE="${nameINT}"
BOOTPROTO=static
UUID="${uuid}"
ONBOOT=yes
IPADDR="${1}"
NETMASK="${NETMASK}"
EOF

A
antares4045, 2021-10-28
@antares4045

you can also do this if the lines are short
printf "str1\nstr2\nstr3" >> /home/2.txt

S
shurshur, 2021-10-29
@shurshur

In addition to the above:
echo -e "str1\nstr2\nstr3" >> file.txt

W
woodsleaf, 2022-04-11
@woodsleaf

cat « EOF | sudo tee /etc/apt/preferences.d/codium.pref
Package: *
Pin: origin download.vscodium.com
Pin-Priority: 100
EOF

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question