files=rm file1.txt
...runs file1.txt
as a command with the environment variable files
set to the value rm
.
This is generally true of any simple command preceded by KEY=VALUE
pairs: Those pairs are treated as environment variables to be set only for the duration of that one command.
Perhaps you instead want:
files=file1.txt
...or:
files=( ) # create an empty array, not a scalar (string) variable.
read number
case $number in
1) files+=( file1.txt ) ;; # or simply: 1) rm file1.txt ;;
2) files+=( file2.txt ) ;; # or simply: 2) rm file2.txt ;;
3) files+=( file3.txt ) ;; # or simply: 3) rm file3.txt ;;
*) echo "This file does not exist" >&2 ; exit 1;;
esac
# ...if collecting filenames in an array, then...
echo "Removing files:" >&2
printf ' %q\n' "${files[@]}" >&2 # ...expand that array like so.
rm -f "${files[@]}" # likewise
To understand why something like cmd='rm file1.txt'
would be -- while correct syntax -- very poor practice and opening yourself up to bugs, see BashFAQ #50.