Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to be sure that two directories are not subdirectories to each other (BASH)
    text
    copied!<p><strong>EDITED:</strong> this is more or less what I came up after @Mechanical's nice input. Any insight?</p> <pre><code>#!/bin/bash path1="$(readlink -e "$1")" path2="$(readlink -e "$2")" EBADARGS=65 function checkArgsNumber() { if test "$#" -ne 2; then echo "ERRORE: this script takes exactly 2 params." exit $EBADARGS fi } function checkExistence() { if [ ! -d $path1 ]; then echo "ERROR: "$1" does not exist" exit $EBADARGS elif [ ! -d "$2" ]; then echo "ERROR: "$2" does not exist" exit $EBADARGS elif [[ -L $path1 ]]; then echo "ERROR: path1 can't be a symbolic link" exit $EBADARGS elif [[ -L $2 ]]; then echo "ERROR: path2 can't be a symbolic link" exit $EBADARGS fi } function checkIfSame() { if [[ $path1 == $path2 ]]; then echo "ERROR: path1 and path2 must be different directories" exit $EBADARGS fi } function checkIfSubdirectories() { if [[ $path1 = *$path2* ]]; then echo "ERROR:"$1" is a $path2 subdirectory" exit $EBADARGS elif [[ $path2 = *$path1* ]]; then echo "ERROR:"$2" is a $path1 subdirectory" exit $EBADARGS elif [[ -e "$(find $path1 -samefile $path2)" ]]; then echo "ERROR:"$(find $path1 -samefile $path2 -print0)" and "$2" have the same inode, $path2 is a $path1 subdirectory" exit $EBADARGS elif [[ -e "$(find $path2 -samefile $path1)" ]]; then echo "ERROR:"$(find $path2 -samefile $path1 -print0)" and "$2" have the same inode, $path1 is a $path2 subdirectory" exit $EBADARGS fi } checkArgsNumber "$@" checkExistence "$@" checkIfSame "$@" checkIfSubdirectories "$@" </code></pre> <p>now.. this should work and I hope it is useful somehow. Could someone explain me how the <code>*$path2*</code> part works? What is the name of this <code>* *</code> operator? Where should I go read about it? </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