I know there's a better way to do this, I'm just not looking in the correct place to figure it out.I have a number of these type of statements (say 1-100, or a list of different filenames).  Basically, I'm doing checks on all of them and then doing the same type of command to them.if [ -f ~/file1 ]; then     if [ -f ~/Backup/file1 ]; then        rm ~/file1;       # Someday, maybe put a filesize or filedate check as well (investigate eval)    else       cp -ip ~/file1 ~/Backup/file1;       rm ~/file1;   fifiThere should be some way to make this a function (loop once thru with file1, then do it again with file2, etc), and not have to copy-and-paste this stuff over and over and over again.I'd like to get something that's clear-ish to newbies, since once I get this working I probably won't look at it again for 5 years, and when I do come back to it, I'll probably have forgotten everything that's not fairly clear.  This does have the virtue of being clear in what's going on :PI've read some code which does this, said, Hmm, that's interesting, when I need to do more than 3-4 if-thens, I should use that.  And then promptly didn't write it down..Some of these files are: filename001, filename002,... filename100.  I also have the same problem for specifically named files, in which case I'd really like to iterate through a list of filenames, and just add new filenames to the list (instead of copy-and-pasting code).I'm not looking to input anything via the commandline, everything will be laid out in the script (so I can test it, and so I can not screwup and typo something I didn't mean to type).  The idea of a datafile that lists each filename one to a line, that the script calls is interesting to me - but I'm not sure how to make that work.  Got a link?Because this can be a lot easier - and more efficient.I know it can be, but it also has to be clear to people who don't program (namely me, in 5 years - when I'm starting from a point where I don't really know how to program, and will have forgotten a lot of things by the time that rolls around (if it doesn't get handed off to someone else)).  I basically take things I can understand and monkey with them until I can I misuse them to my purposes.  Right now, my scripts don't need to be very efficient, since computers are fast enough for the types of things I'm doing.If backup file exists, then I'm just deleting the current file (if it exists - if it doesn't, I want the script to continue onto the next possibility). If backup doesn't exist, I'm copying current file (hopefully if I run overquota or something (other things may be making/sucking up quota during the time of copying) it will just bail with an error, and not have deleted anything unrecoverable) then deleting the current file.I wouldn't mind adding in something(s) to test if the backup file is useful: timestamp (which one is newer?), size (which one is bigger?), hash (did file copy completely and correctly?) - but that's not necessary right now.
I'm copying if-then statements, with slight variations... and I shouldn't have to
scripting
Ok, so you're looking for a loop, I think.cd ~; i=1000; set --until [ $((i+=1)) -gt 1100 ]do    _i=${i#1}      if    [ -f ./file$_i ] &&             [ -f ./Backup/file$_i ]      then  rm ./file$_i      else  set -- ./file$_i $@      fidone[ $# -gt 0 ]                  &&cp -ip $@ ./Backup  &&rm $@That will count up to 100 and handle files between file[001-100]. It builds an array of files needing copying and does the cp -ip at once, at loop close as necessary. You can do the same with rm as well, in fact, if you opted to use a named array rather than the shell array.It is zero-padding the iterator up to 100 (where the initial -gt evaluation cuts it off), but, as written, the script could be fairly easily modified to handle file numbers up to 999.