I found the following script on commandlinefu.com (the example is no longer online):
rmbut() { local x=("$@") IFS=, rm -rf *[!"${x[*]}"] }
It deletes all files and directories, but the names specified on the command line.
Could you explain the following:
$@
IFS
*[!"${x[*]}"]
local x=("$@") , ($@ ).
local x=("$@")
IFS=, .
IFS=,
IFS=, rm -rf *[!"${x[*]}"] , , . * , , , , IFS ( ).
IFS=, rm -rf *[!"${x[*]}"]
*
rmbut a b c
rm -rf *[!a,b,c], , .
rm -rf *[!a,b,c]
I think :
rmbut() { IFS= rm -rf *[!"$*"] }
. IFS null, rm -rf *[!abc], , ( ). , IFS=, ( ).
rm -rf *[!abc]
# x, local x=("$@")
# IFS. , IFS=
IFS=
# , , .. xrm -rf *[!"${x[*]}"]
rm -rf *[!"${x[*]}"]