user1918074
user1918074

Reputation: 29

Bash Script - Piping commands to echo

I have this command :

echo rm $(find "$SD" -type f -mtime "+$MT" -name "*.$TY" -print ) >> ${LOGFILE}

and it prints

rm /u01/oradata/logs/dwf_monitor_datafile.dbf.gz /u01/oradata/logs/dws_monitor_datafile.dbf.gz /u01/oradata/logs/dwd_monitor_datafile.dbf.gz

I want it to instead print

rm /u01/oradata/logs/dwf_monitor_datafile.dbf.gz 
rm /u01/oradata/logs/dws_monitor_datafile.dbf.gz 
rm /u01/oradata/logs/dwd_monitor_datafile.dbf.gz

How, thanks in adcance.

Upvotes: 1

Views: 43

Answers (1)

John1024
John1024

Reputation: 113884

If you actually want to delete the files, you should use find's -delete command. If you are just trying to display nice-looking output, then try:

find "$SD" -type f -mtime "+$MT" -name "*.$TY" -exec echo rm {} \; >>${LOGFILE}

Upvotes: 3

Related Questions