Why does this Bash script not work, to print arguments from the command line?:
cat << EOF > test echo "First arg: $1" echo "Second arg: $2" echo "List of all arg: $@" EOF bash test hello world!
Shell variable expansion .
Quote the EOF , so the cat program knows it is looking for a string .
Remove the ambiguity .
What you are using is called a 'here document' . heredoc .
A here document is a special-purpose code block. It uses a form of I/O redirection to feed a command list to an interactive program or a command, such as ftp, cat, or the ex text editor.
Can turn off the shell expansion by quoting the EOF . 'EOF' .
Advanced Bash-Scripting Guide
cat << 'EOF' > test echo "First arg: $1" echo "Second arg: $2" echo "List of all arg: $@" EOF bash test hello world!