tail -1 file1.txt > variable1 writes to the file
Use command substitution (bash.info 3.5.4, POSIX sh) instead:
variable1="$(tail -1 file1.txt)"
Btw my version of tail from GNU in cygwin doesn't have the
-1 option. Instead, I use
# EREGEX: Replace all whitespace at beginning of line
# NOTE: BSD sed uses a different flag to enable EREGEX, -E.
# EDIT: Dropped -r. \s is already included in BRE.
# Thanks to kos for pointing that out.
# EDIT: Use POSIX [:space:] instead of Perl \s.
variable1="$(sed -e 's/^[[:space:]]*//g' < file1.txt)"
Combined with line selection:
# EDIT: limit the [s]ubstitude operation to the 4th line only, and
# [p]rint directly from s.
variable1="$(sed -ne '4s/^[[:space:]]*//p' < file1.txt)"