Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I want to make my bash to replace word `-mthreads each time I input it with word -pthread. Is such thing possible and how to do it?

share|improve this question
Why???????????? – Alex Chamberlain Oct 20 '12 at 19:23
At the prompt or in scripts. To you want the p to turn into m on the command line as soon as you type the d, or the word replaced upon pressing enter? To you want it unconditionally (-pthreads-safe to be turned into -mthreads-safe?)? Any way to bypass that substitution? Is switching to another shell (like zsh) an option? All of those should be possible with zsh, some of them might be possible with bash. – Stéphane Chazelas Oct 20 '12 at 19:44

In zsh you can do this with a global alias:

alias -g -- -mthreads=-pthread

But if you need to stick with bash, make a shell function to filter the arguments, as @Kyle Jones explained.

share|improve this answer

I don't see any way to make it apply to all command lines, but you can do the substitution per command by writing a shell function for each command for which you'd like the substitution to happen. Example: for gcc you'd write:

function gcc {
   local args=""
   local arg
   for arg in $@
      case $arg in
         -mthreads) arg=-pthreads
      args="$args $arg"
   command gcc $args
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.