简体   繁体   中英

delete file shell script

This question is on one of my assignments. I know how to create the files but i'm stuck on how to delete foo foo1 foo2 and foo4 but not foo3 . and also how to run

$ ksh <  to_delete.shl.

Write a shell script; named to_delete.shl ; that will create file of these files with the rm command. Edit the file and remove foo3 from being deleted The intention is to use the following command to delete these file

$ ksh <  to_delete.shl.

Create test files

touch foo foo1 foo2 foo3 foo4 "foo difficult" "foo
with
newlines"

Write a script to_delete.sh that will make a script to delete the foo files

for f in foo*; do echo "rm \"$f\""; done > to_delete.sh

Edit the file and remove foo3 from being deleted

vi to_delete.sh <<END
:/"foo3"/d
:wq
END

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM