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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:05:31+00:00 2026-06-01T22:05:31+00:00

Possible Duplicate: Shell Script: How to pass command line arguments to an UNIX alias?

  • 0

Possible Duplicate:
Shell Script: How to pass command line arguments to an UNIX alias?

How do I insert arguments into a bash alias?

for example,
whenever I create a new directory & I cd into it most of the time but for that I have to run two commands.

$ mkdir directory
$ cd directory

so, I was wondering if it is possible to create a new directory & switch to it in singly commands. tried to add the following alias in my .bashrc file:

alias mkdir="mkdir $@ && cd $@"

so, I could call it normally mkdir directory & it would create & then switch to that directory. But no dice, it didn’t work!

Any pointers on how can I insert arguments into an alias?

  • 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-01T22:05:32+00:00Added an answer on June 1, 2026 at 10:05 pm

    Consider defining it as a function.

    function mkdir2 {
      mkdir $@
      cd $@
    }
    

    You won’t be able to alias it to mkdir in this way, but it’ll do as you expect.

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

Sidebar

Related Questions

Possible Duplicate: Automatic exit from bash shell script on error How can I have
Possible Duplicate: Split string based on delimiter in bash? i have a shell script
Possible Duplicate: What does “$?” give us exactly in a shell script? What does
Possible Duplicate: Shell Programming: What's the difference between $(command) and command It seems there
Possible Duplicate: Deflate command line tool Yes, I know I can use PHP itself
Possible Duplicate: Something like print END << END; in C++? In a shell script
Possible Duplicate: Run python script without DOS shell appearing I have a python script
Possible Duplicate: Quick-and-dirty way to ensure only one instance of a shell script is
Possible Duplicate: In Vim: How do I delete a word and go into insert
Possible Duplicate: unix shell, getting exit code with piped child is it possible to

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.