Skip to content

Commit

Permalink
Better invocation of bash, BSD workarounds
Browse files Browse the repository at this point in the history
Using `/bin/bash` to invoke bash is effective, but does not allow for
flexability. `/usr/bin/env bash` will load bash from the PATH. This
allows for the user to set the version of bash.

As for the BSD replacements, I basically detect the presence of GNU
versions of the coreutils, and if they are present, create functions
to use them in place of the BSD versions

Helps fix issue jneen#5
  • Loading branch information
tabletcorry committed Jul 29, 2011
1 parent d4d8c79 commit cbf52ba
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 10 deletions.
16 changes: 15 additions & 1 deletion bin/balls
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
#!/bin/bash
#!/usr/bin/env bash

which gsed >/dev/null && sed() {
gsed $@
}
which greadlink >/dev/null && readlink() {
greadlink $@
}
which gmkfifo >/dev/null && mkfifo() {
gmkfifo $@
}
which gcat >/dev/null && cat() {
gcat $@
}

BALLS_LIB=$(dirname $0)/../lib
BALLS_LIB=$(readlink -f "$BALLS_LIB") # expand the ../

Expand Down
2 changes: 1 addition & 1 deletion bin/esh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
BALLS_LIB=$(readlink -f $(dirname $0)/../lib)

shopt -s extglob
Expand Down
2 changes: 1 addition & 1 deletion lib/balls.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
[[ -z "$BALLS_LIB" ]] && BALLS_LIB=.

[[ -z "$BALLS_CONF" ]] && BALLS_CONF=./config.sh
Expand Down
2 changes: 1 addition & 1 deletion lib/cgi.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# /var/www/cgi-bin/balls.sh
[[ -z "$BALLS_CONFIG" ]] && BALLS_CONFIG=$PWD/config.sh

Expand Down
2 changes: 1 addition & 1 deletion lib/http.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

http::parse_request() {
http::read req_line
Expand Down
2 changes: 1 addition & 1 deletion lib/model.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

[[ -z "$BALLS_DB_CREDENTIALS" ]] && BALLS_DB_CREDENTIALS=''
[[ -z "$BALLS_DB" ]] && BALLS_DB='balls'
Expand Down
2 changes: 1 addition & 1 deletion lib/router.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

balls::define_route() {
local verb=$1; shift
Expand Down
2 changes: 1 addition & 1 deletion lib/server.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

_hash() {
echo $$.$(date +'%s.%N').$RANDOM
Expand Down
2 changes: 1 addition & 1 deletion lib/util.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
stderr() {
echo "$@" >&2
}
Expand Down
2 changes: 1 addition & 1 deletion lib/view.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
esh=$(readlink -f $BALLS_LIB/../bin/esh)
render::esh() {
local view="$BALLS_VIEWS/$1"
Expand Down

0 comments on commit cbf52ba

Please sign in to comment.