Fixes for SH, typo, prompt consistency - #1
Conversation
|
doh, i cloned from your fork rather than the cloudnulls ... |
|
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? |
|
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 |
|
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: I am going to try out checking the $SHELL env. Comparison of dash and bash below: |
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