Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>After doing some more searching, I found that comparing the directory content was somewhat of an effective way of verifying that both variables pointed to the same directory.</p> <p>Here is one way to do it:</p> <pre><code>#clear the timetrex cache if [ "$(diff -q $timetrex_cache $ttrexCache_path 2&gt;&amp;1)" = "" ] then #path is valid, OK to do mass delete rm -R ${ttrexCache_path}* echo "Success: TimeTrex cache has been cleared." else #path could be root - don't delete the whole server echo "Error: TimeTrex cache was NOT cleared." fi </code></pre> <p>If one of the directories is an invalid path, the condition catches the problem and doesn't try to delete the directory contents. </p> <p>If the directory paths are different but point to valid directories, the condition statement sees that they have different contents and doesn't try to delete the directory contents.</p> <p>If both directory paths are different and point to valid directories, and the contents of those directories is the same, then the script will delete everything in one of the directories. SO, this is not a foolproof method.</p> <p>A second method can be seen at <a href="https://superuser.com/questions/196572/check-if-two-paths-are-pointing-to-the-same-file">https://superuser.com/questions/196572/check-if-two-paths-are-pointing-to-the-same-file</a>. The problem with this method is that this code does not know the difference between <code>/tmp/timetrex</code> and <code>/tmp/timetrex/</code> which is important when wanting to append a <code>*</code> at the end of the path.</p> <p><strong>In the end, the best solution for this problem is quite simple</strong>. Changing the syntax of the original code is the only thing that needed to be done.</p> <pre><code>#clear the timetrex cache if [ ${timetrex_cache} == ${ttrexCache_path} ] &amp;&amp; [[ "${timetrex_cache: -1}" = "/" ]] then #path is valid, OK to do mass delete rm -R ${ttrexCache_path}* echo "Success: TimeTrex cache has been cleared." else #path could be root - don't delete the whole server echo "Error: TimeTrex cache was NOT cleared." fi </code></pre> <p>Hope this is helpful to someone!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload