I have several Ubuntu servers and there is some behavior that has me curious.
On any newly installed machine (Ubuntu Server 12.04.3 LTS), if I run:
echo "testbla123" | grep -P -o [0-9]*
This will return 123
as expected.
On an older machine (Ubuntu Server 12.04.1 LTS), if I run the same command, I get nothing back, I have to instead run:
echo "testbla123" | grep -P -o "[0-9]*"
After performing an apt-get upgrade
, it will perform without quotes around the regex.
Grep is at the same versions on both machines. I tried comparing dependencies before and after the update for some time without much luck.
I was wondering if anyone knows why this happens?
Chances are you have a file that matches the glob pattern
[0-9]*
on your second machine, and not on the first one. If that's the case, the shell will expand the glob into the file's name before passing that as an argument togrep
.If there is no file that match on the current directory, the shell leaves the glob pattern untouched and passes it as-is to the command.
Always quote parameters that contain shell wildcards if you don't want them to be expanded by the shell.