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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:21:21+00:00 2026-05-16T23:21:21+00:00

I am trying to set up bash completion for a utility script I wrote,

  • 0

I am trying to set up bash completion for a utility script I wrote, so I added the following script to /etc/bash_completion.d:

_mcd()
{
    local cur words
    COMPREPLY=()

    cur="${COMP_WORDS[COMP_CWORD]}"
    words=`mcd-completion-words`
    COMPREPLY=( $(compgen -W "${words}" -- "$cur") )
    return 0
}
complete -F _mcd mcd

The mcd-completion-words script programmatically finds available operators for the command. When I restart bash (or source the script), I can successfully tab complete, but if I do so, I can no longer backspace past a completed character.

Also, if I attempt to list all options (e.g. I attempt to tab complete w/ no word in place), bash adds a tab to the command, which I also cannot backspace.

How can I make bash mimic normal file completion behavior? Any help is appreciated. Thanks!


Here’s a reduced testcase for mcd-completion-words that still exhibits the same behavior. Curiously, Dennis’ case works for me as well (when substituting in words=”one two three”, for example).

#!/usr/bin/env php
<?php

print "one two three four five six seven eight nine";
  • 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-16T23:21:21+00:00Added an answer on May 16, 2026 at 11:21 pm

    Here’s a reduced test case; even an empty `php’ command causes the erroneous completion behaviour:

    $ _mcd() { php -r ""; COMPREPLY=( one ); }
    $ complete -F _mcd mcd
    $ mcd <TAB>            # Becomes 'mcd one' all right
    $ mcd one <BACKSPACE>  # ERROR: doesn't work
    

    This is on machine (Ubuntu) with both bash-3.2.48/bash-4.0.33 & php-5.2.6-3ubuntu4. On another machine (Debian) with bash-3.2.39 & php-5.2.6-1+lenny9, completion & backspace goes all right.

    Using perl -e "" instead of php -r "" also goes all right.

    Don’t know what’s going on, php conflicting with readline? Maybe you can try bug-bash mailing list?

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

Sidebar

Related Questions

I'm trying to set a script that finds the location of bash then uses
I'm trying to set a variable that uses another variable in a bash script:
In Bash programming, I'm trying to set up a script to generate a specific
When trying to set DoMatchParen I get the following error: E492: Not an editor
Trying to set-up a git server on my local dev machine and have been
I am trying to source a bash script containing some environment variables in python.
I'm trying to write a helper function to use in a bash script to
I'm trying to write a BASH script to get my Java program to run(common
I am trying to run a batch script (set of R commands saved in
I am trying to execute a bash script from within my dialplan. The bash

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.