目前shell不支持unicode转义的字符串,bash4.2 alpha支持可行的办法就是做字符替换,给个Python的demo,面向行处理#!/usr/bin/env python# -*- coding: utf-8 -*-import reimport sys def main():for line in sys.stdin: sys.stdout.write(re.sub(r'\uw{4}', lambda e: unichr(int(e.group(0)[2:], 16)).encode('utf-8'), line)
)if __name__ == '__main__': main()复制代码用法:脚本保存为test.py,执行sumomos-MacBook-Pro:py lgr$ echo 'u9ED8u8BA4' | python ./test.py 默认