Building an SQL Reference Object: Commands clarification

I recognize that my initial query might look too abstract, thus for some more context I would like to show you an example, taken from reset.sh in learn git by building an sql reference object course configuration for coderoad:

#!/bin/bash

if [[ ! -a sql_reference ]]
then 
  mkdir sql_reference
fi

find ./sql_reference -not -name '.' -not -name '..' -not -name 'sql_reference' -delete
cp -r ./.freeCodeCamp/sql_reference/. ./sql_reference
mv ./sql_reference/dotgit ./sql_reference/.git

This code is doing the following:
It checks for the presence of a directory named sql_reference, if not it creates it. But then it tries to empty it and delete its contents, regardless if it was created just previously or if it existed before. Afterwards, it copies the content of an established backup and activates the git repository by renaming the dotgit to .git.
When I see this I reason to myself, the emptying of the directory should be only if it does exist, therefore it should be part of the check with if. But then, I have to question, why to go all the trouble to check and delete if it looks like we do not care about the content, at all?
Why not to delete the directory and reconstructed with just a simple copy command?

rm -rf sql_reference                        # This will not exit with failure if no directory exists.
cp -r  .freeCodeCamp/sql_reference .        # It copies the backup to a directory with the same name.
mv sql_reference/dotgit sql_reference/.git  # No need to pre-append the current directory 

I would love to know what the intention was to see if I might be correct.

I moved your question to its own thread. Hopefully, the title is accurate.

1 Like

This thread came from here and makes reference to the initial post.

When we move threads it also adds a link back to the original thread.

But it is totally fine that you made it more obvious as it isn’t super clear what that link means. Anyway, just an FYI.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.