New GitHub issue #95575 from Juksefantomet:<br>

<hr>

<pre>
# Bug report

python file:
```
import subprocess
import re

rc = subprocess.check_output("/home/user/test.sh")
print(rc)
```

bash file:
```
<newline here>
#!bin/bash
echo "Hello World"
```

When executing the subprocess.check_output fails to reckognize the bash script as executable due to the newline.

```
SyntaxError: invalid syntax
Traceback (most recent call last):
  File "/home/user/test.py", line 5, in <module>
    rc = subprocess.check_output('/home/user/test_ip.sh')
  File "/usr/lib64/python2.7/subprocess.py", line 216, in check_output
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
  File "/usr/lib64/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception
OSError: [Errno 8] Exec format error
```

# Your environment

Amazon Linux 2 - VM clean install
python 2.7.18
python 3.7.10

Is this expected behavior? or should there be any expected removing of preceding newlines?

Normal bash script execution works as intended even with newline in place.

</pre>

<hr>

<a href="https://github.com/python/cpython/issues/95575">View on GitHub</a>
<p>Labels: type-bug</p>
<p>Assignee: </p>