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.

This commit is contained in:
vim88 2018-11-28 22:43:18 +02:00 committed by Jack Grigg
parent 5b11b94d27
commit 27f924108c
3 changed files with 35 additions and 1 deletions

View File

@ -1,3 +1,5 @@
#!/usr/bin/env bash
#
# Copyright (c) 2017 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://www.opensource.org/licenses/mit-license.php .

View File

@ -276,6 +276,31 @@ Strings and formatting
`wcstoll`, `wcstombs`, `wcstoul`, `wcstoull`, `wcstoumax`, `wcswidth`,
`wcsxfrm`, `wctob`, `wctomb`, `wctrans`, `wctype`, `wcwidth`, `wprintf`
Scripts
--------------------------
### Shebang
- Use `#!/usr/bin/env bash` instead of obsolete `#!/bin/bash`.
- [*Rationale*](https://github.com/dylanaraps/pure-bash-bible#shebang):
`#!/bin/bash` assumes it is always installed to /bin/ which can cause issues;
`#!/usr/bin/env bash` searches the user's PATH to find the bash binary.
OK:
```bash
#!/usr/bin/env bash
```
Wrong:
```bash
#!/bin/bash
```
Source code organization
--------------------------

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
# Shebang must use python3 (not python or python2)
# Assert expected shebang lines
export LC_ALL=C
EXIT_CODE=0
@ -10,4 +10,11 @@ for PYTHON_FILE in $(git ls-files -- "*.py"); do
EXIT_CODE=1
fi
done
for SHELL_FILE in $(git ls-files -- "*.sh"); do
if [[ $(head -n 1 "${SHELL_FILE}") != "#!/usr/bin/env bash" &&
$(head -n 1 "${SHELL_FILE}") != "#!/bin/sh" ]]; then
echo "Missing expected shebang \"#!/usr/bin/env bash\" or \"#!/bin/sh\" in ${SHELL_FILE}"
EXIT_CODE=1
fi
done
exit ${EXIT_CODE}