#!/usr/bin/env bash
set -euo pipefail

logfile="q"
logpath=$TMPDIR$logfile

if [[ -z "$TMPDIR" ]]; then
	if [[ -e "/system/bin/adb" ]]; then
		# android
		logpath="/data/local/tmp/$logfile"
	else
		logpath="/tmp/$logfile"
	fi
fi

if [[ ! -f "$logpath" ]]; then
	touch $logpath
fi

tail -100f $logpath

#!/usr/bin/env bash
set -euo pipefail

logfile="q"
logpath=$TMPDIR/$logfile

if [[ -z "$TMPDIR" ]]; then
	if [[ -e "/system/bin/adb" ]]; then
		# android
		logpath="/data/local/tmp/$logfile"
	else
		logpath="/tmp/$logfile"
	fi
fi

if [[ ! -f "$logpath" ]]; then
	touch $logpath
fi

tail -100f $logpath

Handle TMPDIR without trailing slash
Handle TMPDIR without trailing slash

Where TMPDIR=/tmp then logpath=/tmpq despite the go library correctly writing to /tmp/q. With this change logpath=/tmp/q when TMPDIR=/tmp, and logpath=/tmp//q when TMPDIR=/tmp/ which still works just fine.