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 . instead of source in shell scripts #97

Closed
gucharbon opened this issue Jan 7, 2020 · 8 comments
Closed

Use . instead of source in shell scripts #97

gucharbon opened this issue Jan 7, 2020 · 8 comments

Comments

@gucharbon
Copy link
Contributor

gucharbon commented Jan 7, 2020

I'm using 18.04.3 LTS (Bionic Beaver) and python 3.7.5
I just created my own repository using cookiecutter.

I ran the script ./scripts/build-push.sh and received the error below:

(venv) [email protected]:/c/Users/monsoon/fastapi/webdemo(21:19:57)$ ./scripts/build-push.sh
./scripts/build-push.sh: 6: ./scripts/build-push.sh: source: not found

After taking a look at the template I saw that /bin/sh is specified in shebang:

#! /usr/bin/env sh

# Exit in case of error
set -e

Ubuntu uses /bin/dash in place of/bin/sh and not /bin/bash. Ubuntu Wiki states that:

The source builtin is a bashism (related checkbashisms warning text: 'source' instead of '.'). Write this simply as . instead.

Isn't there anybody on Ubuntu or Debian which tried to run the scripts and had this error? I searched existing issue but found none.

Edit: I just saw in the README that user should use bash to start scripts (as in the example: TAG=prod FRONTEND_ENV=production bash ./scripts/build-push.sh) but I still feel that this . should be used instead of source to be coherent with shebang and to allow usage of TAG=prod FRONTEND_ENV=production ./scripts/build-push.sh.

Anyway thanks for the awesome work :)

@gucharbon gucharbon changed the title Use . instead of source in scripts/*.sh Use . instead of source in shell scripts Jan 7, 2020
@Shackelford-Arden
Copy link

Shackelford-Arden commented Mar 22, 2020

@gucharbon While that documentation you provided does indicate the use of dash on Ubuntu based systems, if you run the command as shown in the shebang:

/usr/bin/env sh

On an Ubuntu system (tested on Ubuntu 18.04.4) you'll find that this works just fine.

As the documentation page you referenced indicates in the second paragraph from the top:

The default login shell remains bash. Opening a terminal from the menu or shortcut [crtl-alt-t] provides interactive bash. A script run from the desktop or file manager, through the dialogue 'run in terminal' will execute as POSIX dash.

The default shell is still bash.

The benefit of specifying the /usr/bin/env sh at the beginning tells the system to use sh instead of whatever shell you yourself are actively using at the time of script execution.

So, I don't think it's helpful to make the change from source to . here.

@gucharbon
Copy link
Contributor Author

gucharbon commented Mar 23, 2020

@Shackelford-Arden
I don't get your comment. Using source command in a script with /usr/bin/env sh sheebang will result in a failure if you're running on Ubuntu Bionic (18.04).

Unless you explicitely start the script with bash <script_name>.

IMO it is clearly a bug to have a script indicating sh in sheebang and still using source later in the script.

@Shackelford-Arden
Copy link

My apologies, I managed to test incorrectly when I was looking at this. Guess that's what I get for moving too quickly :) You're correct that source does not work as intended in this script.

@StephenBrown2
Copy link
Contributor

Shouldn't it be /usr/bin/env bash, then?

@gucharbon
Copy link
Contributor Author

I think we are thinking a lot for a really small issue 😄

@StephenBrown2 I guess there is no right or wrong between using /usr/bin/env bash in sheebang or using . instead of source.

I don't really care, and I don't think people will want to run the scripts in environments without bash installed by default (like alpine linux for example).

But still, I think that between 2 working solutions, the most portable should always be prefered.

@StephenBrown2
Copy link
Contributor

+1 for . then

@tiangolo
Copy link
Member

Thanks for the discussion here everyone!

Yeah, agreed that source is a bit more readable, but . should work in more environments and that wins in the end 😄

Thanks for the PR with the fix @gucharbon ! 🚀

@github-actions
Copy link

Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.

alejsdev pushed a commit that referenced this issue Dec 19, 2024
* Implement pagination for team invitations

* Fix key
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

No branches or pull requests

4 participants