Skip to content

Shebang #! invocation doesn't work as intended on *BSD targets #18

@filippsen

Description

@filippsen

Bug report

#!/usr/local/bin/space [args] does not work on *BSD boxes

Steps to reproduce 1

a.sh

$ cat a.sh
#!./b.sh These args should be all arg1

b.sh

$ cat b.sh
#!/bin/env bash
echo "1 (all shebang args): $1"
echo "2 (should be filename): $2"
echo "Here should come user args"
echo 3: $3
echo 4: $4
echo 5: $5
echo 6: $6
echo 7: $7
echo 8: $8

Output

$ ./a.sh A B C
<nothing>

Changing a.sh shebang line

$ cat a.sh 
#!/usr/bin/env ./b.sh arg1 arg2 arg3 arg4
$ ./a.sh A B C
1 (all shebang args): arg1
2 (should be filename): arg2
Here should come user args
3: arg3
4: arg4
5: ./a.sh
6: A
7: B
8: C

Steps to reproduce 2

Setup 1-a

Config

cat a.sh 
#!./b.sh These args should be all arg1

cat b.sh
cat b.sh 
#!/usr/bin/env bash
echo "1 (all shebang args): $1"
echo "2 (should be filename): $2"
echo "Here should come user args"
echo 3: $3
echo 4: $4
echo 5: $5
echo 6: $6
echo 7: $7
echo 8: $8

Run

./a.sh A B C D
<nothing>
echo $?
0

Setup 1-b (a.sh shebang variation)

Config

cat a.sh 
#!/usr/bin/env ./b.sh arg1 arg2 arg3 arg4

Run

./a.sh A B C D 
env: ./b.sh arg1 arg2 arg3 arg4: No such file or directory

Setup 1-c (b.sh shebang variation)

Config

cat b.sh 
#!/usr/local/bin/bash
echo "1 (all shebang args): $1"
echo "2 (should be filename): $2"
echo "Here should come user args"
echo 3: $3
echo 4: $4
echo 5: $5
echo 6: $6
echo 7: $7
echo 8: $8

Run

./b.sh 123 213 444 
1 (all shebang args): 123
2 (should be filename): 213
Here should come user args
3: 444
4:
5:
6:
7:
8:

Setup 2 - shebang_bsd

Run

./test/exit_status_cases/shebang_bsd.sh
env: space ! -m utils /waitforfile/ -- 1 !: No such file or directory

Expected output

$ ./a.sh A B C
1 (all shebang args): These args should be all arg1
2 (should be filename): ./a.sh
Here should come user args
3: A
4: B
5: C
6:
7:
8:
---------------

References

http://www.in-ulm.de/~mascheck/various/shebang/

More examples

Currently not working in FreeBSD.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions