Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
2  
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
add comment

2 Answers 2

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
add comment

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 $@
   do
      case $arg in
         -mthreads) arg=-pthreads
      esac
      args="$args $arg"
   done
   command gcc $args
}
share|improve this answer
add comment

Your Answer

 
discard

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.