0

This .bashrc function is working on the command line, its a nice bash one line'er.

but moving it into the bash profile and it stops working ?

replaceInAll (){ find . -name "$1" -print | xargs sed -i 's/$2/$3/g' }

what am i not getting wright with this ?

dmc
  • 401
  • 4
  • 14
  • 1
    Are you sure `.bash_profile` is sourced for your shell? It's only sourced for login shells, not all interactive shells. – chepner Aug 29 '14 at 13:04
  • I am in linux box so its .bashrc, and I have a have a functions working fine e.g grepall (){ find . -name "$1" | xargs -I % sh -c 'echo %; grep "$2" %; echo "" ' _ "$@"; } – dmc Aug 29 '14 at 13:11
  • If your terminal emulator starts a non-login interactive shell, then you have to define the function in `.bashrc`. Functions are not exported, so your shells will not inherit the function from your initial login shell. (You could, however, try exporting the functions from `.bash_profile` using `export -f replaceInAll` and logging back in to see if the function is propagated to other shells. It's much simpler to just define the function in the correct file, though.) – chepner Aug 29 '14 at 13:12
  • mm, well my function was available for me to use from the cmd. but I swapped it out into the bash_profile but no change. the function is not doing the replacing – dmc Aug 29 '14 at 13:22
  • 1
    Did you change the quotes when you moved it? The single quotes used in the `sed` argument prevent `$2` and `$3` from being expanded. – chepner Aug 29 '14 at 13:25

1 Answers1

0

This works

replaceInAll (){ find . -name "$1" -print | xargs sed -i s/"$2"/"$3"/g }

dmc
  • 401
  • 4
  • 14