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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:10:35+00:00 2026-05-31T13:10:35+00:00

I just learned about aliases in bash. I created one like so: alias=cd $directory

  • 0

I just learned about aliases in bash. I created one like so:

alias="cd $directory"

where $directory is from use input. In another shell script, I can launch a subshell like so:

( bash )

which brings me to the subshell, where, if I run cd, I go to the alias, cd $directory. This is great and it seems to be working as expected.

What I’m looking for is for when the subshell is launched, the cd happens automatically, so I tried:

( bash | cd )

thinking it would launch the subshell and cd to the user-entered $directorybut it’s not working. How can I go about getting this to work? I also tried ( bash -c cd) to no avail.

Thanks.

  • 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-31T13:10:36+00:00Added an answer on May 31, 2026 at 1:10 pm

    The reason that ( bash | cd ) doesn’t work is that each command in a pipeline is run in a separate subshell, so ( bash | cd ) is essentially equivalent to ( ( bash ) | ( cd ) ) (except that the latter launches even more subshells, of course). Instead, you should be able to write:

    ( cd ; bash )
    

    (which runs cd before running bash) since bash will inherit a copy of the execution environment of the subshell it was launched from.

    By the way — are you sure you want to create cd as an alias this way? That seems error-prone and confusing to me. I think it would be better to create a shell function that cds to the user-specified directory:

    function cd_user () { cd "$directory" ; }
    
    ( cd_user ; bash )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just learned about jquery's .makeArray and I am trying to use JSON.stringify to
I have just learned about the possibility to use OTHER_CODE_SIGN_FLAGS to specify the keychain
My boss just told me that he learned about fast VB6 algorithms from a
Just learned about sigacation, also implemented another timer to make it more interesting. #include
So I'm learning java. I'm one month in and I just learned about constructors.
Ive just learned java and asked a question about my one line calculator it
I just learned about how the Java Collections Framework implements data structures in linked
I just learned about ngrep , a cool program that lets you easily sniff
I just learned about how to include FxCop on a build. But it's slow
I just posted this question and learned about <see cref=> , however when i

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.