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 POSIX sh instead of GNU Bash #4296

Open
yukiisbored opened this Issue Sep 4, 2018 · 17 comments

Comments

Projects
None yet
4 participants
@yukiisbored
Copy link
Contributor

yukiisbored commented Sep 4, 2018

It would be a lot better to replace every shell script which uses bash on the shebang (#!/bin/bash) to portable POSIX sh (#!/bin/sh). Even though people may argue that we can just install Bash, Bash is not part of the POSIX standard which is what most UNIX-based/UNIX-like operating systems oblige to.

So, in order to make porting it to other UNIXes (Unices) easier, I think using POSIX sh would be a good start.

yukiisbored added a commit to yukiisbored/cuberite that referenced this issue Sep 4, 2018

@LoganDark

This comment has been minimized.

Copy link

LoganDark commented Sep 9, 2018

If you ever encounter a UNIX-like system without bash, installing bash is trivial.

@yukiisbored

This comment has been minimized.

Copy link
Contributor

yukiisbored commented Sep 9, 2018

@LoganDark

This comment has been minimized.

Copy link

LoganDark commented Sep 9, 2018

Doesn't it sound like this would be a very trivial pull request then?

@yukiisbored

This comment has been minimized.

Copy link
Contributor

yukiisbored commented Sep 9, 2018

@LoganDark Actually, yes but I want to make sure nothing is broken and I've been quite busy lately.

@LoganDark

This comment has been minimized.

Copy link

LoganDark commented Sep 9, 2018

set is bash-specific, FYI.

@yukiisbored

This comment has been minimized.

Copy link
Contributor

yukiisbored commented Sep 9, 2018

@LoganDark Not all of them. on top of my head the bash specific options is -o pipefail forgot what are the others.
http://pubs.opengroup.org/onlinepubs/009696799/utilities/set.html
https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html

@LoganDark

This comment has been minimized.

Copy link

LoganDark commented Sep 9, 2018

Nevermind. I ran help set in sh, and it also happens to be an sh builtin as well. I was doing my test in fish by accident...

@yukiisbored

This comment has been minimized.

Copy link
Contributor

yukiisbored commented Sep 9, 2018

Anyway, the end goal for me is to get Cuberite ported on OpenBSD and FreeBSD (maybe NetBSD as well?) and I would rather just get this thing to upstream rather than writing silly one-liner patches on ports.

@LoganDark

This comment has been minimized.

Copy link

LoganDark commented Sep 9, 2018

If you're too busy to test it on the OS you're porting to, what's the point?

Doesn't matter if this gets done now or when you decide to test it. It's all the same in the end, just one allows for testing when you have time for it and one causes someone else to have to test it.

@yukiisbored

This comment has been minimized.

Copy link
Contributor

yukiisbored commented Sep 9, 2018

@LoganDark I run OpenBSD on my server and I use FreeBSD on my desktop.

Testing it would be easy but I just don't have the time at the moment, probably a couple of weeks I can get them done along with ShellCheck on CI to guarantee POSIX compliance.

@LoganDark

This comment has been minimized.

Copy link

LoganDark commented Sep 9, 2018

Testing it would be easy but I just don't have the time at the moment

Then if it gets done now, you'll have to wait till then anyway.

@VioletasTheThird

This comment has been minimized.

Copy link

VioletasTheThird commented Dec 25, 2018

Would just like to say, on most UNIX systems, /bin/sh is actually just a symlink to your default shell, so if you test anything on a system with a non standard shell then things will act as if it was the non standard shell rather than sh.

@LoganDark

This comment has been minimized.

Copy link

LoganDark commented Dec 25, 2018

@VioletasTheThird yes, but if you use only sh syntax, then most non-standard shells (that people would install on their systems as the default) should run the script fine.

@VioletasTheThird

This comment has been minimized.

Copy link

VioletasTheThird commented Dec 26, 2018

@LoganDark My point is more that you wont be able to truely test whether the code is 100% compliant since you will still be running it in bash or whatever

@LoganDark

This comment has been minimized.

Copy link

LoganDark commented Dec 26, 2018

@VioletasTheThird if you test it with POSIX sh it should work on most other systems though

Most systems have BusyBox sh anyway, test it on one of those and systems that use a different shell should support it.

fish uses () around subcommands rather than `, but I don't know of any fucked-up distros that symlink it to /bin/sh

@yukiisbored

This comment has been minimized.

Copy link
Contributor

yukiisbored commented Jan 1, 2019

Hey guys, I have cuberite/docker-build-image#3 in eternal pending. I need it to get POSIX sh compliance verification.

@bearbin

This comment has been minimized.

Copy link
Member

bearbin commented Jan 1, 2019

@yukiisbored Sorry for that, I have now merged it :)

yukiisbored added a commit to yukiisbored/cuberite that referenced this issue Jan 6, 2019

yukiisbored added a commit to yukiisbored/cuberite that referenced this issue Jan 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment