I'm attempting to write a shell script for BusyBox (v1.27.1) wherein the script, in part, needs to extract the last item from a list/multiline variable, which contains a list of absolute file paths. I've been working on this most of the day, and still no joy. What am I doing wrong?
TARGET_DIRECTORY="/usr/bin" # can be any valid location
ALL_LOG_FILES=$(find $TARGET_DIRECTORY -maxdepth 1 -regex '.*\.log')
LAST_LINE=$($(`echo $ALL_LOG_FILES`) | tail -1) # broken here
echo "last line=$LAST_LINE"
$ALL_LOG_FILES
is subject to word splitting, so there is no "last line" - see related Echo newline with quotes – steeldriver Nov 03 '20 at 22:05echo $ALL_LOG_FILES
vsecho "$ALL_LOG_FILES"
. BTW you seem to have more layers of command substitution than you need there -LAST_LINE=$(echo "$ALL_LOG_FILES" | tail -1)
should be sufficient. – steeldriver Nov 03 '20 at 22:18