4 ms·
Not sure what you are saying, bash behaves as bash when invoked as /bin/bash, and Bourne-shell-ish when invoked as /bin/sh. Lots more detail in the man page. I
by ericbarrett 5y ago
Not sure what you are saying, bash behaves as bash when invoked as /bin/bash, and Bourne-shell-ish when invoked as /bin/sh. Lots more detail in the man page.
I've never seen use of aliases in a bash script...? They are generally for CLI convenience.
- chasil 5y agoAlias expansion within scripts is mandated by POSIX. 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 found
- ericbarrett 5y agoThat's very nice, it's POSIX-compliant when invoked as #!/bin/sh and sane when invoked as #!/bin/bash — exactly what I'd want.
- chasil 5y agoIf you want a portable script, then you don't want that behavior.
- ericbarrett 5y agoThen I wouldn't put #!/bin/bash at the top.
- chasil 5y agoYour problem there is Ubuntu/Debian. A 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.
- jjnoakes 5y agoSure but someone putting #!/bin/bash at the top of their script, written for non-POSIX bash, won't have that issue...