I have a cross platform product that gets deployed to several Linux distros and I’m busy changing one of its startup scripts. Currently the script uses /bin/sh as interpreter. My question is. How safe am I if I change this to /bin/bash, will there be some cases that bash is not installed or something. Why does all the scripts in /etc/init.d use /bin/sh. Are there some stuff that will break when using bash?
Share
If portability is a goal, you would be doing yourself a disservice to assume
bashwas installed. That is not to say thatbashwon’t be installed 99% of the time, but it’s the 1% that gets ya.bashis a POSIX Compliant shell, so unless you need/want to use bash-only syntax, I would not just change the interpreter line to#!/bin/bashon a whim; it buys you nothing with a script that works with#!/bin/shBecause they don’t want the system to go down if the admin decides he wants to save hard drive space by deleting
bashbecause his favorite shell iszshIt’s more the other way around. If you have a script with bash-only (non-POSIX) syntax, for example
[[ ]]or process substitution<( ), this will break if you change the interpreter from#!/bin/bashto#!/bin/sh