I usually stay on StackOverflow but I think on this topic you guys are much more experts here.So today's exercise is weird, I have to write a script.sh and in it do whatever I can to prevent test.txt from being deleted but the catch is that the last line has to be rm -f test.txtI don't really know much about shell (I usually do c/objective-c)  so I picked up a book, haven't finished it but still have no clue of how to do that.I thought about permissions, but the script will be given all permission when tested so it's not an option...(I don't know if it matters but the script will be run on OS X).
Prevent a file from being deleted even after rm -f
shell script;osx
On Linux, you could use the immutable flag using chattr to achieve read-only on a filesystem level (requires appropriate permissions though). I don't use OS X and do not know if it has something similar, but you could achieve after script is run, test.txt still exist using:#!/bin/shmv test.txt test.baktrap mv test.bak test.txt EXITrm -f test.txtThis script renames test.txt to test.bak and renames it back when the script has exited (after rm -f test.txt). This is not truly read-only, but unless you kill -KILL your script, it should preserve your data at least.Alternative idea, if you insist having that line in it, why not exit earlier?#!/bin/sh# do your thingexit# my boss insisted to have the 'rm' line below.rm -f test.txtAlternative that turns rm into a function that does nothing:#!/bin/sh# do your thingrm() {    # this function does absolutely nothing    : # ... but it has to contain something}rm -f test.txtSimilar to the function method above, but using the deprecated alias command to alias rm to the true built-in that does nothing (but returing a true exit code):#!/bin/sh# do your thingalias rm=truerm -f test.txtAlternative that removes rm from the environment (assuming that there is no rm built-in):#!/bin/sh# do your thingPATH= # now all programs are gone, mwuahaha# gives error: bash: rm: No such file or directoryrm -f test.txtAnother one that changes $PATH by using a stub rm program (using /tmp as search path):#!/bin/sh# do your thing>/tmp/rm # create an empty rm filechmod +x /tmp/rmPATH=/tmprm -f test.txtFor more information about built-ins, run help <built-in> for details. For example:true: true    Return a successful result.    Exit Status:    Always succeeds.For other commands, use man rm or look in the manual page, man bash.