Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6145019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:44:05+00:00 2026-05-23T18:44:05+00:00

EDITED: this is more or less what I came up after @Mechanical’s nice input.

  • 0

EDITED: this is more or less what I came up after @Mechanical’s nice input. Any insight?

#!/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 "$@"

now.. this should work and I hope it is useful somehow.
Could someone explain me how the *$path2* part works? What is the name of this * * operator? Where should I go read about it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:44:06+00:00Added an answer on May 23, 2026 at 6:44 pm

    Some problems:

    Stylistic

    You should probably quote the entire argument to echo, as

        echo "ERROR: $1 is a subdirectory of $(readlink -e "$2")"
    

    Without the quotes around the argument to echo, you are technically passing each word as its own parameter: echo "ERROR:somedir" "is" "a" "subdirectory"…. Since echo prints its parameters in the order given, separated by spaces, the output is the same in your case. But semantically it’s not what you want.

    (An example where it would be different:

    echo foo          bar
    

    would print foo bar.)

    Error message doesn’t work properly

    If the arguments don’t exist

    $ ./check.sh nonexistent1 nonexistent2
    ERROR:nonexistent1 is a subdirectory of 
    

    Obviously, this is irrelevant if you’ve already checked they exist.

    You similarly need to check for corner cases such as where the parameters refer to the same directory:

    $ mkdir a b
    $ ln -s ../a b/c
    $ ./check.sh a b/c
    ERROR:a is a subdirectory of /dev/shm/a
    

    Doesn’t detect symbolic links

    $ mkdir a b
    $ ln -s ../a b/c
    $ ./check.sh a b
    

    gives no error message.

    Doesn’t detect mount --bind

    $ mkdir a b b/c
    $ sudo mount --bind a b/c
    $ ./check.sh a b
    

    gives no error message.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NB: This question has been extensively edited to make it more relevant, for completeness
I edited this question after i found a solution... i need to understand why
I have edited this post with my question writen in a more simple way
** This question has been edited to make it simpler and more focused **
I originally posted a much simpler (and less helpful) question, and have edited this
I've edited this quite a bit and bolded my question at this point. I
I'm using Wamp 2.2, edited conf/extra/httpd-vhosts.conf edited this file to add VirtualHosts , but
Edited Question: This should be clear. using System; namespace UpdateDateTimeFields { class Program {
This is a sample (edited slightly, but you get the idea) of my XML
edited, this is it function handleDate( timestamp ) { var n=new Date(), t, ago

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.