Can I assume that bash is installed

I have a cross-platform product that is deployed on several Linux distributions, and am busy modifying one of its startup scripts. Currently, the script uses / bin / sh as an interpreter. My question is. As far as I'm sure, if I change this to / bin / bash, will there be cases when bash is not installed or something else. Why all scripts in /etc/init.d use / bin / sh. Are there any things that will be broken when using bash?

+4
source share
3 answers

Is it possible to assume that bash is installed

If portability is the goal, you have to make yourself poorly convinced that bash supposed to be installed. This does not mean that bash will not be installed in 99% of cases, but it is 1% that ya gets.

As far as I'm sure, if I change this to / bin / bash, will there be cases where bash is not installed or something

bash is POSIX Compliant , so if you don't need / don't need bash -only syntax, I would not just change the line of the translator to #!/bin/bash on a whim; he doesn't buy anything with a script that works with #!/bin/sh

Why are all the scripts in /etc/init.d use / bin / sh

Because they do not want the system to crash if the administrator decides that he wants to save space on the hard drive by removing bash , because his favorite shell is zsh

Are there any things that will break when using bash?

This is the opposite. If you have a script with the syntax bash -only (non-POSIX), for example [[ ]] or process substitution <( ) , this will break if you change the interpreter from #!/bin/bash to #!/bin/sh

+11
source

It depends on how you use the cross application.

In case it works with "large" Linux distributions, feel free to assume bash, but with smaller CDs or custom installations, bash is not data. Indeed, if you leave Linux, I will be even more careful in assuming bash (in which case the location / bin / bash is also not specified).

The reason that the /etc/init.d scripts always use / bin / sh is because it is defined on most platforms.

I do not think that the material will break if you use bash, bash implements the same "functions" as sh, but not vice versa. In short, if you don't need special bash functions, use / bin / sh

+2
source

Assume installed bash falls into the same category as

  • Worldwide VAX
  • All i386 processors
  • All Free Unixen is Linux
  • All IDEs are Eclipse
  • All compilers - gcc

If you maintain portability (at least with a POSIX shell), you save most of your work in the future. The day will come when you find yourself in another company, with a different OS and a different shell. Then your knowledge of shell portability will pay big dividends.

The mantra, to tell yourself and others, is: "Assumption is the mother of all debauchery." :-)

0
source

Source: https://habr.com/ru/post/1337277/


All Articles