Skip to main content
Became Hot Network Question
added 1 character in body
Source Link
ilkkachu
  • 148.1k
  • 16
  • 268
  • 441

Imagine you have a silly script test.sh to which arguments are passed that would look like this:

bash test.sh arg1 arg2 arg3

with test.sh being a silly script that displays its command line:

#!/bin/bash
echo "$0 $*$*"

I would like to do the same using bash heredoc << to feed the script to bash. So I tried this :

bash <<'EOF' -- arg1 arg2 arg3
echo "$0 $*"
EOF

But it fails with error

bash: arg1: No such file or directory

Any idea ?

Imagine you have a silly script test.sh to which arguments are passed that would look like this:

bash test.sh arg1 arg2 arg3

with test.sh being a silly script that displays its command line:

#!/bin/bash
echo "$0 $*

I would like to do the same using bash heredoc << to feed the script to bash. So I tried this :

bash <<'EOF' -- arg1 arg2 arg3
echo "$0 $*"
EOF

But it fails with error

bash: arg1: No such file or directory

Any idea ?

Imagine you have a silly script test.sh to which arguments are passed that would look like this:

bash test.sh arg1 arg2 arg3

with test.sh being a silly script that displays its command line:

#!/bin/bash
echo "$0 $*"

I would like to do the same using bash heredoc << to feed the script to bash. So I tried this :

bash <<'EOF' -- arg1 arg2 arg3
echo "$0 $*"
EOF

But it fails with error

bash: arg1: No such file or directory

Any idea ?

edited tags
Link
AdminBee
  • 23.6k
  • 25
  • 56
  • 77
Source Link

Bash : how to pass arguments to a heredoc script

Imagine you have a silly script test.sh to which arguments are passed that would look like this:

bash test.sh arg1 arg2 arg3

with test.sh being a silly script that displays its command line:

#!/bin/bash
echo "$0 $*

I would like to do the same using bash heredoc << to feed the script to bash. So I tried this :

bash <<'EOF' -- arg1 arg2 arg3
echo "$0 $*"
EOF

But it fails with error

bash: arg1: No such file or directory

Any idea ?