sed exclamation
Hi,
trying to automatically disable some DAEMONS in /etc/rc.conf. This requires inserting ecxlamation signs itno the file. The example command Code:
echo Hi?|sed 's/?/!/' but Code:
echo netfs|sed 's/netfs/!netfs/' Where does the difference come from? |
Odd. Try this one:
Code:
echo 'Hi?' | sed 's/?/\!/' |
Quote:
I suppose the difference is that the ? is probably interpreted as a specia character by the shell. In my system, Mac OS X 10.6, with the default shell (Terminal.app) I correctly get: Code:
~ $ echo Hi?|sed 's/?/!/' bye giammy |
Quote:
Code:
echo 'Hi?' | sed 's/?/\!/' Which is why I checked my bash history and discovered this: Code:
echo Hi?|sed 's/?/!' Let's hope you won't have to see more questions like this one. I really appreciate your help. |
It may not be the problem you're experiencing, but it should be pointed out that ! is generally seen as a special character in interactive shells. It has the function of starting a history expansion, and if followed by a number or string that references a previous command, it will insert it into the current command at that location. It will also likely spit out an error if followed by something unrecognized as one.
This even works inside of double quotes, but single quotes or the backslash will escape it. Try this, for example: Code:
echo "Hi?" | sed "s/?/!!/" Note though that this isn't usually a problem in scripts, only the command line. See the HISTORY EXPANSION section in the bash man page for details. |
All times are GMT -5. The time now is 05:54 AM. |