'Bash Script Multiple Commands together With EOF

Are there ways to run the following commands in one line? It writes some shell script commands into a file and then continues to do other commands.

eg.

cat <<\EOF > ./test.sh
cd "$HOME"
echo "$PWD" # echo the current path
EOF; chmod +x ./test.sh

The example above does not work and will not write to the test.sh file and change the file permission.

which the purpose of this is to run as follows

cat <<\EOF > ./test.sh
cd "$HOME"
echo "$PWD" # echo the current path
EOF

chmod +x ./test.sh


Solution 1:[1]

Well, you can easily put different commands on one line, separating them with a semicolon (;), like this:

ls;ls

Which is the same as:

ls
ls

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dominique