Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use /usr/bin/env sh instead of direct path of sh

Merged
merged 1 commit into from Feb 17, 2022
Merged

Use /usr/bin/env sh instead of direct path of sh #1051

merged 1 commit into from Feb 17, 2022

Conversation

skhaz
Copy link
Contributor

@skhaz skhaz commented Sep 24, 2021

According with the best practices of shell scripting, the right way to invoke the shebang is #!/usr/bin/env shell

Reference: https://www.cyberciti.biz/tips/finding-bash-perl-python-portably-using-env.html

@Maxim-Mazurok
Copy link

Maxim-Mazurok commented Sep 27, 2021

This doesn't work in my Ubuntu 20 (WSL):

$ /usr/bin/env shell
/usr/bin/env: ‘shell’: No such file or directory

@Maxim-Mazurok
Copy link

Maxim-Mazurok commented Sep 27, 2021

I wanted to use bash, this worked for me:

# Bash sets the BASH environment variable, so if it is not set, then we
# are running in a different shell, so manually run ourselves in BASH.
# source: https://github.com/typicode/husky/issues/971#issuecomment-846431179
if [ -z "${BASH:-}" ]; then
  exec bash "$0" "$@"
fi

Credit: #971 (comment)

@nathandao
Copy link

nathandao commented Sep 27, 2021

This doesn't work in my Ubuntu 20 (WSL):

$ /usr/bin/env shell
/usr/bin/env: ‘shell’: No such file or directory

hmmm, does using /usr/bin/env sh instead of shell work for you? 🤔

@nathandao
Copy link

nathandao commented Sep 27, 2021

@skhaz since you're already on it, would it be possible to update other parts of the code that are using #!/bin/sh as well? The files I found are:

.husky/commit-msg
.husky/pre-commit
docs/README.md
./husky.sh

@Maxim-Mazurok
Copy link

Maxim-Mazurok commented Sep 27, 2021

This doesn't work in my Ubuntu 20 (WSL):

$ /usr/bin/env shell
/usr/bin/env: ‘shell’: No such file or directory

hmmm, does using /usr/bin/env sh instead of shell work for you? 🤔

Yes, it does. Opens up sh for me. Same with /usr/bin/env bash - opens up bash for me.

@Maxim-Mazurok
Copy link

Maxim-Mazurok commented Sep 27, 2021

Also, I can see that in the linked article they mention #!/usr/bin/env bash not #!/usr/bin/env shell:

Let us find out why is it a good idea to use #!/usr/bin/env bash instead of #!/bin/bash as shebang?
(source)

So, I guess that it was a typo, @skhaz?

@skhaz
Copy link
Contributor Author

skhaz commented Sep 27, 2021

@Maxim-Mazurok do you want bash instead of sh? I am not sure if macOS cames with bash, sh is a more secure option

@skhaz
Copy link
Contributor Author

skhaz commented Sep 27, 2021

@nathandao done, changed all references of /bin/sh

@Maxim-Mazurok
Copy link

Maxim-Mazurok commented Sep 27, 2021

@Maxim-Mazurok do you want bash instead of sh? I am not sure if macOS cames with bash, sh is more secure option

Yes, I want bash because I am letting developers configure if they want to lint and unit test their code in pre-commit hook. I'm storing scrips in array, and then passing this array of scripts to npm-run-all. Didn't find an easy way to do this with sh. Also, I'm only concerned about Ubuntu and Windows. And windows git client comes with git bash, so I guess it's pretty safe for me. Mac may think differently ;)

@Maxim-Mazurok
Copy link

Maxim-Mazurok commented Sep 27, 2021

This is my code:

scripts=("npm:sort -- --check" "npm:spell-check" "npm:prettier:check")
[[ "$PRE_COMMIT_LINT" == true ]] && scripts+=("npm:test:lint")
[[ "$PRE_COMMIT_TEST_UNIT" == true ]] && scripts+=("npm:test:unit")
npx -y concurrently --kill-others-on-fail "${scripts[@]}"

But sh/bash is not related to this issue PR, so never mind :)

@skhaz
Copy link
Contributor Author

skhaz commented Sep 27, 2021

@Maxim-Mazurok you can use bash by invoking the script inside the hook, for example:

Your hook

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

your_script.sh || exit

And in your_script.sh you have bash specific things:

#!/bin/bash

your code for bash

Or... Manually change to bash your hook

@Maxim-Mazurok
Copy link

Maxim-Mazurok commented Sep 29, 2021

Or... Manually change to bash your hook

This doesn't work (changing shebang in hook), because husky.sh resets shell to be sh.

@Maxim-Mazurok you can use bash by invoking the script inside the hook, for example:

Your hook

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

your_script.sh || exit

And in your_script.sh you have bash specific things:

#!/bin/bash

your code for bash

This is a good idea, thanks

@stale
Copy link

stale bot commented Nov 28, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Nov 28, 2021
@Maxim-Mazurok
Copy link

Maxim-Mazurok commented Nov 28, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Occuring an activity

@stale stale bot removed the wontfix label Nov 28, 2021
@skhaz
Copy link
Contributor Author

skhaz commented Nov 29, 2021

Bump

@stale
Copy link

stale bot commented Jan 28, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jan 28, 2022
@Maxim-Mazurok
Copy link

Maxim-Mazurok commented Jan 28, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Occuring an activity

@stale stale bot removed the wontfix label Jan 28, 2022
@typicode typicode merged commit 81b2e2e into typicode:main Feb 17, 2022
@typicode
Copy link
Owner

typicode commented Feb 17, 2022

Thank you for the PR 👍

kodiakhq bot pushed a commit to ToppleTheNun/npm-lockfile-version that referenced this issue May 8, 2022
[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [husky](https://typicode.github.io/husky) ([source](https://togithub.com/typicode/husky)) | [`7.0.4` -> `8.0.0`](https://renovatebot.com/diffs/npm/husky/7.0.4/8.0.0) | [![age](https://badges.renovateapi.com/packages/npm/husky/8.0.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/husky/8.0.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/husky/8.0.0/compatibility-slim/7.0.4)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/husky/8.0.0/confidence-slim/7.0.4)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>typicode/husky</summary>

### [`v8.0.0`](https://togithub.com/typicode/husky/releases/v8.0.0)

[Compare Source](https://togithub.com/typicode/husky/compare/v7.0.4...v8.0.0)

#### What's Changed

##### Feats

-   feat: add `husky -` prefix to logged global error messages by [@&#8203;joshbalfour](https://togithub.com/joshbalfour) in [typicode/husky#1092
-   feat: show `PATH` when command not found to improve debuggability
-   feat: drop Node 12 support
-   feat: skip install if `$HUSKY=0`

##### Fixes

-   fix: hook script use `/usr/bin/env sh` instead of direct path of `sh` by [@&#8203;skhaz](https://togithub.com/skhaz) in [typicode/husky#1051
-   fix: actually set 'husky_skip_init' as readonly in `./husky.sh` by [@&#8203;hyperupcall](https://togithub.com/hyperupcall) in [typicode/husky#1104
-   fix: force `basename`/`dirname` to treat `$0` as an argument by [@&#8203;mataha](https://togithub.com/mataha) in [typicode/husky#1132
-   fix: remove `git.io` links by [@&#8203;renbaoshuo](https://togithub.com/renbaoshuo) in [typicode/husky#1136

##### Docs

-   docs: fix uninstall via npm by [@&#8203;pddpd](https://togithub.com/pddpd) in [typicode/husky#1033
-   docs: add dog emoji as favicon by [@&#8203;jamiehaywood](https://togithub.com/jamiehaywood) in [typicode/husky#1095
-   docs: replace deprecated `npx --no-install` option with `npx --no` by [@&#8203;sibiraj-s](https://togithub.com/sibiraj-s) in [typicode/husky#1070
-   docs: add `pnpm` installation by [@&#8203;MohamadKh75](https://togithub.com/MohamadKh75) in [typicode/husky#1139

##### Chore

-   chore: update workflows by [@&#8203;tiziodcaio](https://togithub.com/tiziodcaio) in [typicode/husky#1125

</details>

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

 **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/ToppleTheNun/npm-lockfile-version).
hoonoh pushed a commit to hoonoh/aws-spot-price that referenced this issue May 9, 2022
[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [husky](https://typicode.github.io/husky) ([source](https://togithub.com/typicode/husky)) | [`7.0.4` -> `8.0.0`](https://renovatebot.com/diffs/npm/husky/7.0.4/8.0.0) | [![age](https://badges.renovateapi.com/packages/npm/husky/8.0.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/husky/8.0.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/husky/8.0.0/compatibility-slim/7.0.4)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/husky/8.0.0/confidence-slim/7.0.4)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>typicode/husky</summary>

### [`v8.0.0`](https://togithub.com/typicode/husky/releases/v8.0.0)

[Compare Source](https://togithub.com/typicode/husky/compare/v7.0.4...v8.0.0)

#### What's Changed

##### Feats

-   feat: add `husky -` prefix to logged global error messages by [@&#8203;joshbalfour](https://togithub.com/joshbalfour) in [typicode/husky#1092
-   feat: show `PATH` when command not found to improve debuggability
-   feat: drop Node 12 support
-   feat: skip install if `$HUSKY=0`

##### Fixes

-   fix: hook script use `/usr/bin/env sh` instead of direct path of `sh` by [@&#8203;skhaz](https://togithub.com/skhaz) in [typicode/husky#1051
-   fix: actually set 'husky_skip_init' as readonly in `./husky.sh` by [@&#8203;hyperupcall](https://togithub.com/hyperupcall) in [typicode/husky#1104
-   fix: force `basename`/`dirname` to treat `$0` as an argument by [@&#8203;mataha](https://togithub.com/mataha) in [typicode/husky#1132
-   fix: remove `git.io` links by [@&#8203;renbaoshuo](https://togithub.com/renbaoshuo) in [typicode/husky#1136

##### Docs

-   docs: fix uninstall via npm by [@&#8203;pddpd](https://togithub.com/pddpd) in [typicode/husky#1033
-   docs: add dog emoji as favicon by [@&#8203;jamiehaywood](https://togithub.com/jamiehaywood) in [typicode/husky#1095
-   docs: replace deprecated `npx --no-install` option with `npx --no` by [@&#8203;sibiraj-s](https://togithub.com/sibiraj-s) in [typicode/husky#1070
-   docs: add `pnpm` installation by [@&#8203;MohamadKh75](https://togithub.com/MohamadKh75) in [typicode/husky#1139

##### Chore

-   chore: update workflows by [@&#8203;tiziodcaio](https://togithub.com/tiziodcaio) in [typicode/husky#1125

</details>

---

### Configuration

📅 **Schedule**: "after 5pm on Friday,every weekend" (UTC).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

 **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/hoonoh/aws-spot-price).

Co-authored-by: Renovate Bot <bot@renovateapp.com>
kodiakhq bot pushed a commit to mheob/vscode-snippets that referenced this issue May 14, 2022
[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [husky](https://typicode.github.io/husky) ([source](https://togithub.com/typicode/husky)) | [`^7.0.4` -> `^8.0.0`](https://renovatebot.com/diffs/npm/husky/7.0.4/8.0.1) | [![age](https://badges.renovateapi.com/packages/npm/husky/8.0.1/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/husky/8.0.1/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/husky/8.0.1/compatibility-slim/7.0.4)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/husky/8.0.1/confidence-slim/7.0.4)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>typicode/husky</summary>

### [`v8.0.1`](https://togithub.com/typicode/husky/releases/v8.0.1)

[Compare Source](https://togithub.com/typicode/husky/compare/v8.0.0...v8.0.1)

-   fix: use POSIX equality operator

### [`v8.0.0`](https://togithub.com/typicode/husky/releases/v8.0.0)

[Compare Source](https://togithub.com/typicode/husky/compare/v7.0.4...v8.0.0)

#### What's Changed

##### Feats

-   feat: add `husky -` prefix to logged global error messages by [@&#8203;joshbalfour](https://togithub.com/joshbalfour) in [typicode/husky#1092
-   feat: show `PATH` when command not found to improve debuggability
-   feat: drop Node 12 support
-   feat: skip install if `$HUSKY=0`

##### Fixes

-   fix: hook script use `/usr/bin/env sh` instead of direct path of `sh` by [@&#8203;skhaz](https://togithub.com/skhaz) in [typicode/husky#1051
-   fix: actually set 'husky_skip_init' as readonly in `./husky.sh` by [@&#8203;hyperupcall](https://togithub.com/hyperupcall) in [typicode/husky#1104
-   fix: force `basename`/`dirname` to treat `$0` as an argument by [@&#8203;mataha](https://togithub.com/mataha) in [typicode/husky#1132
-   fix: remove `git.io` links by [@&#8203;renbaoshuo](https://togithub.com/renbaoshuo) in [typicode/husky#1136

##### Docs

-   docs: fix uninstall via npm by [@&#8203;pddpd](https://togithub.com/pddpd) in [typicode/husky#1033
-   docs: add dog emoji as favicon by [@&#8203;jamiehaywood](https://togithub.com/jamiehaywood) in [typicode/husky#1095
-   docs: replace deprecated `npx --no-install` option with `npx --no` by [@&#8203;sibiraj-s](https://togithub.com/sibiraj-s) in [typicode/husky#1070
-   docs: add `pnpm` installation by [@&#8203;MohamadKh75](https://togithub.com/MohamadKh75) in [typicode/husky#1139

##### Chore

-   chore: update workflows by [@&#8203;tiziodcaio](https://togithub.com/tiziodcaio) in [typicode/husky#1125

</details>

---

### Configuration

📅 **Schedule**: "before 3am on Friday" (UTC).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

 **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/mheob/vscode-snippets).
aviator-app bot pushed a commit to airplanedev/node-sdk that referenced this issue Jun 24, 2022
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [husky](https://typicode.github.io/husky) ([source](https://togithub.com/typicode/husky)) | [`7.0.4` -> `8.0.1`](https://renovatebot.com/diffs/npm/husky/7.0.4/8.0.1) | [![age](https://badges.renovateapi.com/packages/npm/husky/8.0.1/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/husky/8.0.1/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/husky/8.0.1/compatibility-slim/7.0.4)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/husky/8.0.1/confidence-slim/7.0.4)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>typicode/husky</summary>

### [`v8.0.1`](https://togithub.com/typicode/husky/releases/tag/v8.0.1)

[Compare Source](https://togithub.com/typicode/husky/compare/v8.0.0...v8.0.1)

-   fix: use POSIX equality operator

### [`v8.0.0`](https://togithub.com/typicode/husky/releases/tag/v8.0.0)

[Compare Source](https://togithub.com/typicode/husky/compare/v7.0.4...v8.0.0)

#### What's Changed

##### Feats

-   feat: add `husky -` prefix to logged global error messages by [@&#8203;joshbalfour](https://togithub.com/joshbalfour) in [typicode/husky#1092
-   feat: show `PATH` when command not found to improve debuggability
-   feat: drop Node 12 support
-   feat: skip install if `$HUSKY=0`

##### Fixes

-   fix: hook script use `/usr/bin/env sh` instead of direct path of `sh` by [@&#8203;skhaz](https://togithub.com/skhaz) in [typicode/husky#1051
-   fix: actually set 'husky_skip_init' as readonly in `./husky.sh` by [@&#8203;hyperupcall](https://togithub.com/hyperupcall) in [typicode/husky#1104
-   fix: force `basename`/`dirname` to treat `$0` as an argument by [@&#8203;mataha](https://togithub.com/mataha) in [typicode/husky#1132
-   fix: remove `git.io` links by [@&#8203;renbaoshuo](https://togithub.com/renbaoshuo) in [typicode/husky#1136

##### Docs

-   docs: fix uninstall via npm by [@&#8203;pddpd](https://togithub.com/pddpd) in [typicode/husky#1033
-   docs: add dog emoji as favicon by [@&#8203;jamiehaywood](https://togithub.com/jamiehaywood) in [typicode/husky#1095
-   docs: replace deprecated `npx --no-install` option with `npx --no` by [@&#8203;sibiraj-s](https://togithub.com/sibiraj-s) in [typicode/husky#1070
-   docs: add `pnpm` installation by [@&#8203;MohamadKh75](https://togithub.com/MohamadKh75) in [typicode/husky#1139

##### Chore

-   chore: update workflows by [@&#8203;tiziodcaio](https://togithub.com/tiziodcaio) in [typicode/husky#1125

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 5am on Thursday" in timezone America/New_York, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

 **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants