开发者

Can I set the LANG variable from within sed?

I wrote a s开发者_Go百科cript to replace certain expressions and remove others, but it failed in cleaning up special characters. Setting LANG=C solved that, but is it possible to set that environment variable from within sed?


No, but you don't have to. You can set the envirinment variable before executing your sed command.


You can set the environment variable so that it's active only for the single invocation of a command or script:

LANG=C sed ...

or

LANG=C sedscript


If your script is a sed script, you can just bump that part down and put it into a standard shell script. e.g.

#!/usr/bin/sed -f

1 {
    x
    s/^$/          /
    s/^.*$/&&&&&&&&/
    x
}

into

#!/bin/sh

export LANG=C

/usr/bin/sed '
1 {
    x
    s/^$/          /
    s/^.*$/&&&&&&&&/
    x
}
' "$@"

(from an example in the sed info document.)

With the trailing "$@", it should pass arguments and handle stdin the same way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜