From 3d636f77e6c7057742db358b38a9695993909e2c Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 7 Dec 2019 13:25:50 +0100 Subject: [PATCH] explain REGEX usage vs. file globbing --- bashbot.sh | 6 +++--- commands.sh | 2 +- dev/hooks/pre-commit.sh | 2 +- mycommands.sh | 5 ++++- test/d-JSON.sh-test.sh | 2 +- test/d-process_inline-test.sh | 2 +- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 1924c81..26d0a93 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -153,7 +153,7 @@ fi ############### # load modules -for modules in ${MODULEDIR:-.}/*.sh ; do +for modules in "${MODULEDIR:-.}"/*.sh ; do # shellcheck source=./modules/aliases.sh [ -r "${modules}" ] && source "${modules}" "source" done @@ -615,7 +615,7 @@ start_bot() { find "${DATADIR}" -type p -delete find "${DATADIR}" -size 0 -name "*.log" -delete # load addons on startup - for addons in ${ADDONDIR:-.}/*.sh ; do + for addons in "${ADDONDIR:-.}"/*.sh ; do # shellcheck source=./modules/aliases.sh [ -r "${addons}" ] && source "${addons}" "startbot" "${DEBUG}" done @@ -653,7 +653,7 @@ bot_init() { [ -d "${OLDTMP}" ] && { mv -n "${OLDTMP}/"* "${DATADIR}"; rmdir "${OLDTMP}"; } [ -f "modules/inline.sh" ] && rm -f "modules/inline.sh" # load addons on startup - for addons in ${ADDONDIR:-.}/*.sh ; do + for addons in "${ADDONDIR:-.}"/*.sh ; do # shellcheck source=./modules/aliases.sh [ -r "${addons}" ] && source "${addons}" "init" "${DEBUG}" done diff --git a/commands.sh b/commands.sh index aa87795..d0a681b 100644 --- a/commands.sh +++ b/commands.sh @@ -39,7 +39,7 @@ Get the code in my [GitHub](http://github.com/topkecleon/telegram-bot-bash) # load modues on startup and always on on debug if [ "${1}" = "source" ] || [[ "${1}" = *"debug"* ]] ; then # load all readable modules - for modules in ${MODULEDIR:-.}/*.sh ; do + for modules in "${MODULEDIR:-.}"/*.sh ; do # shellcheck source=./modules/aliases.sh [ -r "${modules}" ] && source "${modules}" "${1}" done diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index fdb1952..a7f75f5 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -21,7 +21,7 @@ echo "............................" unset IFS; set -f # check for shellcheck -if which shellcheck >/dev/null 2>&1; then +if command -v shellcheck >/dev/null 2>&1; then echo " Test all scripts with shellcheck ..." else echo "Error: shellcheck is not installed. Install shellcheck or delete $0" diff --git a/mycommands.sh b/mycommands.sh index c3a6643..9a7c815 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -16,7 +16,10 @@ res="" # To enable this option in your bot, send the /setinline command to @BotFather. export INLINE="0" # Set to .* to allow sending files from all locations -export FILE_REGEX='/home/user/allowed/.*' +# NOTE: this is a regex, not shell globbing! you must use a valid egex, +# '.' matches any charater and '.*' matches all remaining charatcers! +# additionally you must escape special charaters with '\', e.g. '\. \? \[ \*" to match them literally +export FILE_REGEX='^/home/user/allowed/.*' # example: run bashbot over TOR # export BASHBOT_CURL_ARGS="--socks5-hostname 127.0.0.1:9050" diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh index 50be422..90436cf 100755 --- a/test/d-JSON.sh-test.sh +++ b/test/d-JSON.sh-test.sh @@ -20,7 +20,7 @@ do [ "${i}" = "1" ] && echo " ... JSON.sh -s -b -n" [ "${i}" = "2" ] && echo " ... JSON.sh" set +f - for jsonfile in ${REFDIR}/*.in + for jsonfile in "${REFDIR}"/*.in do set -f [ "${i}" = "1" ] && "${JSON}" -s -b -n <"${jsonfile}" >"${jsonfile}.out-${i}" diff --git a/test/d-process_inline-test.sh b/test/d-process_inline-test.sh index 379d4a0..ff2bf97 100755 --- a/test/d-process_inline-test.sh +++ b/test/d-process_inline-test.sh @@ -29,7 +29,7 @@ source <( printf 'UPD=( %s )' "$(sed <<<"${UPDATE}" -E -e 's/\t/=/g' -e 's/=(tru echo "Check process_inline ..." for i in 1 2 do - [ "${i}" = "1" ] && ! which python >/dev/null 2>&1 && continue + [ "${i}" = "1" ] && ! command -v python >/dev/null 2>&1 && continue [ "${i}" = "1" ] && echo " ... with JsonDecode Phyton" && unset BASHBOT_DECODE [ "${i}" = "2" ] && echo " ... with JsonDecode Bash" && export BASHBOT_DECODE="yes" set -x