Skip to content

Commit

Permalink
Simplified logic and quoted some parameters
Browse files Browse the repository at this point in the history
* `command; if [ $? -ne 0 ]; then foo; fi` can be simplified to `if command; then foo; fi` which can be simplified to `command || foo`.
* There is no need to stipulate the return code to `exit` since it will adopt the failure code of the last command executed.
  • Loading branch information
Bilge committed Mar 12, 2015
1 parent 54e1511 commit 161d0d9
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions redis-bash-cli
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,17 @@ done
shift $((${OPTIND} - 1))
if [ "${REDISHOST}" != "" ] && [ "${REDISPORT}" != "" ]
then
exec 6<>/dev/tcp/${REDISHOST}/${REDISPORT} # open fd
if [ $? -ne 0 ]; then
exit 1
fi
# open fd
exec 6<>/dev/tcp/"$REDISHOST"/"$REDISPORT" || exit
else
echo "Wrong arguments"
exit 255
fi
[ "${AUTH}" != "" ] && redis-client 6 AUTH ${AUTH} > /dev/null
[ "${REDISDB}" != "" ] && redis-client 6 SELECT ${REDISDB} > /dev/null
[ "${AUTH}" != "" ] && redis-client 6 AUTH "$AUTH" > /dev/null
[ "${REDISDB}" != "" ] && redis-client 6 SELECT "$REDISDB" > /dev/null
for ((z=1;z<=${REPEAT};z++))
do
redis-client 6 "${@}"
if [ $? -ne 0 ]; then
exit 1
fi
redis-client 6 "$@" || exit
[ ${DELAY} -gt 0 ] && sleep ${DELAY}
done
exec 6>&- #close fd

0 comments on commit 161d0d9

Please sign in to comment.