Skip to content

Commit 0936e25

Browse files
committed
Merge #14831: Scripts and tools: Use #!/usr/bin/env bash instead of #!/bin/bash.
688f665 Scripts and tools & Docs: Used #!/usr/bin/env bash instead of obsolete #!/bin/bash, added linting for .sh files shebang and updated the Developer Notes. (vim88) Pull request description: As it was discussed in [#13510](bitcoin/bitcoin#13510), it is better to use `#!/usr/bin/env bash` instead of `#!/bin/bash`. Tree-SHA512: 25f71eb9a6a0cdc91568b5c6863205c5fe095f77a69e633503a2ac7805bd9013af8538e538c0c666ce96a28e3f43ce7a8df5f08d4ff007723bb588d85674f2da
2 parents 127b30c + 688f665 commit 0936e25

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed

contrib/qos/tc.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env bash
2+
#
13
# Copyright (c) 2017 The Bitcoin Core developers
24
# Distributed under the MIT software license, see the accompanying
35
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

doc/developer-notes.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Developer Notes
2828
- [Strings and formatting](#strings-and-formatting)
2929
- [Variable names](#variable-names)
3030
- [Threads and synchronization](#threads-and-synchronization)
31+
- [Scripts](#scripts)
32+
- [Shebang](#shebang)
3133
- [Source code organization](#source-code-organization)
3234
- [GUI](#gui)
3335
- [Subtrees](#subtrees)
@@ -602,6 +604,31 @@ TRY_LOCK(cs_vNodes, lockNodes);
602604
}
603605
```
604606
607+
Scripts
608+
--------------------------
609+
610+
### Shebang
611+
612+
- Use `#!/usr/bin/env bash` instead of obsolete `#!/bin/bash`.
613+
614+
- [*Rationale*](https://github.com/dylanaraps/pure-bash-bible#shebang):
615+
616+
`#!/bin/bash` assumes it is always installed to /bin/ which can cause issues;
617+
618+
`#!/usr/bin/env bash` searches the user's PATH to find the bash binary.
619+
620+
OK:
621+
622+
```bash
623+
#!/usr/bin/env bash
624+
```
625+
626+
Wrong:
627+
628+
```bash
629+
#!/bin/bash
630+
```
631+
605632
Source code organization
606633
--------------------------
607634

src/qt/res/movies/makespinner.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env bash
2+
#
13
# Copyright (c) 2014-2015 The Bitcoin Core developers
24
# Distributed under the MIT software license, see the accompanying
35
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

test/lint/lint-python-dead-code.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
#
33
# Copyright (c) 2018 The Bitcoin Core developers
44
# Distributed under the MIT software license, see the accompanying

test/lint/lint-python-shebang.sh renamed to test/lint/lint-shebang.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
# Shebang must use python3 (not python or python2)
2+
# Assert expected shebang lines
33

44
export LC_ALL=C
55
EXIT_CODE=0
@@ -10,4 +10,11 @@ for PYTHON_FILE in $(git ls-files -- "*.py"); do
1010
EXIT_CODE=1
1111
fi
1212
done
13+
for SHELL_FILE in $(git ls-files -- "*.sh"); do
14+
if [[ $(head -n 1 "${SHELL_FILE}") != "#!/usr/bin/env bash" &&
15+
$(head -n 1 "${SHELL_FILE}") != "#!/bin/sh" ]]; then
16+
echo "Missing expected shebang \"#!/usr/bin/env bash\" or \"#!/bin/sh\" in ${SHELL_FILE}"
17+
EXIT_CODE=1
18+
fi
19+
done
1320
exit ${EXIT_CODE}

0 commit comments

Comments
 (0)