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 6792539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:58:56+00:00 2026-05-26T17:58:56+00:00

I’m making this tiny program in Shell: #*************************************************************** # Function. # NAME: chk_df #

  • 0

I’m making this tiny program in Shell:

#***************************************************************
# Function.
# NAME: chk_df
# Synopsis:
# Check if a local directory (dirName) exist and has a file (fileName).
# 
# 
# The return codes are the following:
# 99 : dirName does not exists
#  0 : dirName exists and has fileName
#  1 : dirName exists and has not fileName
#
# Parameters:
# In values: dirName <string> fileName <string>
# Out values: returnCode <int>
# 
# How to use:
# chk_df dirName fileName
#***************************************************************
chk_df(){
   # Check the number of arguments that could be passed.
   # In this case, two, dirName, fileNAme.
   if [[ ${#@} != 2 ]]; then
       echo "Error ...Use [Function]: chk_df <dirName> <fileName>"
       echo "Ex: chk_df /foo lola.txt"
       exit
   fi   

   DIR=$1
   FILE=$2      

   [[ ! -d $DIR ]] && return 99
   [[ -d $DIR && ! -e $DIR/$FILE ]] && return 1
   [[ -d $DIR && -e $DIR/$FILE ]] && return 0

}

Because I need to check if a file is in a directory, I did this (horrible?) patch $DIR/$FILE , but things like this could happen:

I) If we do: chk_df /foo lola.txt
We get: /foo/lola.txt

II) If we do: chk_df /foo/ lola.txt
We get: /foo//lola.txt [Notice the //]

In both cases the code seems to work. Why? I read that backslash acts like a space. So, could I put n backslash without unknown problems?

Could I leave it like that or it will bring problems? Is there a difference? UNIX assume it to the right way?

EXTRA QUESTION: why I can not do the returns with negative numbers? This is: return -1

  • 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-26T17:58:57+00:00Added an answer on May 26, 2026 at 5:58 pm

    / , //, or any string of consecutive slashes have the same meaning according to the POSIX standard, with the exception that they may have a different meaning at the beginning of a path (so /foo and //foo may denote different objects). Linux does not use this exception, so any number of consecutive slashes always means the same thing as a single /.

    (The exception is there to cater to the needs of other Unix-like systems that use leading // to denote a network path.)

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm making a simple page using Google Maps API 3. My first. One marker
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.