How can I save the output of this command into a var and still remove the files?
rm -vri files | wc -l
How can I save the output of this command into a var and still remove the files?
rm -vri files | wc -l
$ touch file1 file2
$ out=$(rm -vri file1 file2 | wc -l)
rm: remove regular empty file ‘file1’? y
rm: remove regular empty file ‘file2’? y
$ echo $out
2
As you can see, using the normal var=$(command)
method works.
This also works when running it from a script. Obviously, you do need to provide the input (e.g. running it from cron won't work).