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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:04:30+00:00 2026-05-30T16:04:30+00:00

As I known, C-u M-x shell can be used to run multiple shells. But

  • 0

As I known, “C-u M-x shell” can be used to run multiple shells.
But how to define a function to do the same thing as “C-u M-x shell” do ?

  • 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-30T16:04:31+00:00Added an answer on May 30, 2026 at 4:04 pm
    (defun my-named-shell ()
      "Equivalent to C-u M-x shell RET"
      (interactive)
      (shell (get-buffer
              (read-buffer
               "Shell buffer: "
               (generate-new-buffer-name "*shell*")))))
    

    I used describe-function and find-function to examine the behaviour of shell, and its interactive declaration in particular, and then I just copied the necessary code to turn that into an argument for a non-interactive call to the shell function (but wrapping it in get-buffer so as to provide a buffer argument).

    I’ve actually left out some code which dealt with remote files, because the comments in that code seemed a bit confused. If you weren’t in the habit of using C-u M-x shell in buffers accessing remote files via Tramp, that omission won’t affect you.

    That all said, an even simpler (and more complete) approach is simply:

    (defun my-named-shell ()
      "Equivalent to C-u M-x shell RET"
      (interactive)
      (let ((current-prefix-arg '(4)))
        (call-interactively 'shell)))
    

    For more information, refer to https://stackoverflow.com/a/9388058/324105

    In this instance current-prefix-arg could be any non-nil value, but I think it’s a good habit to use a value that C-u actually generates.

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

Sidebar

Related Questions

I've known several operations we can do to variables in shell, e.g: 1) #
According to Marcin Ciura's Optimal (best known) sequence of increments for shell sort algorithm
I known that with subversion you can attach arbitrary properties to each files. In
I know that when you are on shell, the only commands that can be
I'm relatively new to Unix shell scripting. Here's my problem. I've used this script...
I have a TabControl region in Shell.xaml: <TabControl Name=TabRegionControl prism:RegionManager.RegionName=TabRegion /> The user can
so far, I've successfully used the following function to retrieve the IWebBrowser2 pointer to
I know if I nice a shell script (ie: before it runs) all processes
I know this is supposed to output what kind of shell I'm using, which
This is a crude korn shell script that someone else wrote. I don't know

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.