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

  • Home
  • SEARCH
  • 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 8443269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:05:33+00:00 2026-06-10T09:05:33+00:00

The question is in the title. I could not find anything on google, so

  • 0

The question is in the title. I could not find anything on google, so im hoping someone here can explain this to me.

I am using debian 6.0.5 and the shell assigned to the executing user in the /etc/passwd file is /bin/bash

So, simply writing cd ~ works and brings me to the users home directory.

test -d "~/some_dir" returns false in an if statement ( some_dir exsits )

Edit:
Sorry I should’ve been more clear as of why I was writing /bin/bash cd ~ instead of cd ~: I am writing a bash script with #!/bin/bash and the above mentioned if statement ends up in the false clause.

  • 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-06-10T09:05:34+00:00Added an answer on June 10, 2026 at 9:05 am

    The options for any command line are expanded before the command is run, even for internal commands. Whatever shell you’re using to run /bin/bash cd ~ is presumably interpreting the tilde literally rather than a special character that expands to your home directory.

    As a test, try creating a directory by that name and see if the error goes away.

    > mkdir ./~
    > /bin/bash cd ~
    

    Note that the cd command needs to be done within your running shell to be useful. When you change the working directory of a sub-shell, and then the sub-shell exits, you’ll find yourself back where you started.

    UPDATE:

    From within a bash script, you should be able to use the $HOME environment variable, which should consistently contain your home directory. I’m not aware what conditions would cause tilde expansion to fail, but I’ve always used $HOME.

    Also, when determining whether you can change into a particular directory, you have the option of being explicit and returning useful status:

    unset err
    if [[ ! -d "$somedir" ]]; then
      err="Can't find $somedir"
    elif [[ ! -r "$somedir" ]]; then
      err="Can't read $somedir"
    fi
    
    if [[ -n "$err" ]]; then
      echo "$ERROR: $err" >&2
      exit 1
    fi
    
    cd "$somedir"
    

    Or, you can just try the CD and look at its results.

    if ! cd "$somedir"; then
      echo "ERROR: $somedir not availble"
      exit 1
    fi
    

    Detailed error reports are handy, but if you don’t need them, keeping your code small has advantages as well.

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

Sidebar

Related Questions

Sorry i could not find a proper title to this question. I have generated
I could not find a better title for my question, but you are welcome
Sorry could not find a better title for my question. Basically what I noticed
The question is in the title... I searched but couldn't find anything. Edit: I
Its a very basic question - but i could not find the answer to
Excuse the question title, couldn't think how to describe this.. Basically, using a few
I know this question has been asked multiple times (however, I could still not
This question seems to get asked a lot, but I can't find an answer
Not entirely sure my question title describes what I want to do, but couldn't
Sorry for the title, I couldn't argue something better. Here is my question: Is

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.