At least for Debian and Ubuntu, that's why we start bash scripts with #!/bin/bash, of course.
Your point is valid for Busybox, though.
At least for Debian and Ubuntu, that's why we start bash scripts with #!/bin/bash, of course.
Your point is valid for Busybox, though.
That will also fail spectacularly, as bash does not behave the same when called as /bin/bash as it does when it is /bin/sh.
I have principally noticed that aliases are not expanded in scripts unless a shopt is issued, which violates POSIX.
Forcing POSIXLY_CORRECT might also help.
Knowing when to switch into and out of this mode, and what impact it has, is a more advanced subject that should not burden those learning the Borne family.
It is better to start with Almquist, or another pure POSIX implementation, with documentation specific to standard adherence.
More advanced shell features should wait.
Without a nuanced understanding of standards, extensions, and platform availability, new bash users will get large amounts of shell usage that doesn't work.
To avoid that frustration, learn POSIX. That works everywhere that matters.
I've never seen use of aliases in a bash script...? They are generally for CLI convenience.
When bash is not in POSIX mode, it violates the standard.
$ ll /bin/sh
lrwxrwxrwx. 1 root root 4 Nov 24 08:40 /bin/sh -> bash
$ cat s1
#!/bin/sh
alias p=printf
p hello\\n
$ cat s2
#!/bin/bash
alias p=printf
p world\\n
$ ./s1
hello
$ ./s2
./s2: line 3: p: command not foundA bash script that runs as /bin/sh might not run as /bin/bash, until you set POSIXLY_CORRECT.
Easiest solution there is to move it to a better shell, usually a Korn variant.
Another major user of a pdksh descendent is Android (mksh), with a truly massive install base.
Some of the bash problem, besides portability, is GPLv3. That was a major factor for Apple. I don't want my script portability linked to corporate patent issues. For this and other reasons, I don't use bash-specific features, ever.
You should feel free to continue to write portable scripts.
That is horrible advice for anyone who is just starting out though and they should stick with #!/bin/bash and not worry about it until they actually want to consider platforms other than Linux. Portability is the wrong thing for people who are learning to focus on.
It is also bad advice for most system administrators at most businesses since they won't have those alternative *nixes either, and its a best practice to minimize how many different operating systems you have to care about.
Almquist is in Ubuntu for two reasons: speed and standards compliance.
These may not be important to you, but they are to a great many people, and the horrible advice in this case is to disregard these factors.
People who start out with linux should use that. Most companies, particularly HNey startups, should use that and nothing bad will happen.
Most people don't have to care about portability, shouldn't use /bin/sh, and shouldn't learn about Almquist. Your advice does not favors to the bulk of people who just need to get shit done.
If they do wind up working in an environment where it is important, they can teach themselves the differences at that point, or else ask someone like us to review their code (and there's an automated linter out there).
You aren't the Main Character, most people don't need to care about the same things that you do.