bash-it: sed error when loading .bashrc

I installed bash_it follow the instruction. When I run source ~/.bashrc, there may be some error in sed. and I get:

○ → source ~/.bashrc sed: invalid option – E Usage: sed [OPTION]… {script-only-if-no-other-script} [input-file]…

-n, --quiet, --silent suppress automatic printing of pattern space -e script, --expression=script add the script to the commands to be executed -f script-file, --file=script-file add the contents of script-file to the commands to be executed -i[SUFFIX], --in-place[=SUFFIX] edit files in place (makes backup if extension supplied) -c, --copy use copy instead of rename when shuffling files in -i mode (avoids change of input file ownership) -l N, --line-length=N specify the desired line-wrap length for the `l’ command –posix disable all GNU extensions. -r, --regexp-extended use extended regular expressions in the script. -s, --separate consider files as separate rather than as a single continuous long stream. -u, --unbuffered load minimal amounts of data from the input files and flush the output buffers more often –help display this help and exit –version output version information and exit

If no -e, --expression, -f, or --file option is given, then the first non-option argument is taken as the sed script to interpret. All remaining arguments are names of input files; if no input files are specified, then the standard input is read.

E-mail bug reports to: bonzini@gnu.org . Be sure to include the word sed'' somewhere in theSubject:‘’ field.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 1
  • Comments: 26 (20 by maintainers)

Most upvoted comments

Hey, guys,

I tried fixed this problem myself.

cd .bash_it/

find . -name "*.bash" -type f | xargs sed -i "/sed -E/ s/sed -E/sed -r/g"

I replaced all sed -E with sed -r through above commands.

Update: Notice: All above is a temporary fix for CentOS 5.11 & sed 4.1.5, and is not suitable for Mac OS X.

Yes, I meet this issue too on private cloud environment. Looking for someone to contribute a PR on this.

@edubxb Here’s an idea on how to make this less invasive: How about doing the check for the OS only once, e.g. in lib/helpers.bash and then setting an environment variable there, e.g.

case $OSTYPE in
  darwin*)
    # OSX specific code
    BASH_IT_SED_EXTREGEX="-E"
    ;;
  *)
    # Other OS, GNU/Linux (commonly)
    BASH_IT_SED_EXTREGEX="-r"
    ;;
esac

and then wherever we use sed, we use this variable, e.g.

sed $BASH_IT_SED_EXTREGEX ...

This will be less invasive than having the check several times.

BTW: Here’s a nice way of detecting whether sed supports the -E flag without testing simply for the OS (e.g. in case someone has installed the GNU version of sed on OS X): https://developer.apple.com/library/mac/documentation/OpenSource/Conceptual/ShellScripting/PortingScriptstoMacOSX/PortingScriptstoMacOSX.html - scroll down to the sed heading:

STRING="$(echo 'xy' | sed -E 's/(x)y/\1/' 2> /dev/null)"
if [ "$STRING" = "x" ] ; then
    SEDERE="-E"
else
    SEDERE="-r"
fi
...
sed $SEDERE ...

How about using that?