Skip to content

Fixes for SH, typo, prompt consistency - #1

Open
s-j-h wants to merge 3 commits into
walbenzi:masterfrom
s-j-h:master
Open

Fixes for SH, typo, prompt consistency#1
s-j-h wants to merge 3 commits into
walbenzi:masterfrom
s-j-h:master

Conversation

@s-j-h

@s-j-h s-j-h commented Jan 24, 2013

Copy link
Copy Markdown

Added the data centre names to the prompt & fixed a typo,

For some reason I instinctively use "sh scriptname" with this sort of thing, so:

I've got rid of the bash specific alias of == to = inside of [] and stopped sh skipping straight over the sanity check (I didn't notice there was supposed to be one before reading the source) by giving a variable name to the read -p line

@s-j-h

s-j-h commented Jan 24, 2013

Copy link
Copy Markdown
Author

doh, i cloned from your fork rather than the cloudnulls ...

@s-j-h s-j-h closed this Jan 24, 2013
@walbenzi

Copy link
Copy Markdown
Owner

I was taking a look at this, to see what I would do. I am going to try to reopen this and do a selective merge (never tried in github). I like the typo fix.

I am not sure about the other changes. Instead what I think would be interesting (and something I have never done) is test that the script is being run in bash as specified in the shebang. Depending on the whims of the sysadmin (or distribution) and your own chosen environment, /usr/bin/sh could be a symlink to dash, bash, zsh, csh, ksh, etc. You can think of it like this: it might be like typing /usr/bin/python scriptname.sh.

It does bring up a thing I have never error tested: "Is my bash script executing in bash, and if not exit 1 with a warning". Do you know how that might be written?

@walbenzi walbenzi reopened this Jan 24, 2013
@ghost ghost assigned walbenzi Jan 24, 2013
@s-j-h

s-j-h commented Jan 24, 2013

Copy link
Copy Markdown
Author

I've submitted the same pull request to cloudnull now, but sure go for it,

iirc single equals is the posix compliant way of doing things, so should be more portable, i guess when you run "sh scriptname" on ubuntu it must turn on some sort of strict mode as it was choking on the "==" and skipping the sanity check even though it clearly is still running in bash.

afaik shebang only comes into play if you chmod scriptname +x then ./scriptname, so you could have the script check its own file attrbutes & check $SHELL or run test output of which /bin/sh is /bin/bash

@walbenzi

Copy link
Copy Markdown
Owner

Actually, check it out: you are running dash, which is a stripped down lightweight version of bash. You can verify it by doing the following:
which sh #Should be /bin/sh
ls -l /usr/bin/sh #It is a symlink to /bin/dash

I am going to try out checking the $SHELL env.

Comparison of dash and bash below:
http://princessleia.com/plug/2008-JP_bash_vs_dash.pdf

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants