Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 将unicode字符作为utf8从文件中回显_Bash_Macos_Shell_Unicode - Fatal编程技术网

Bash 将unicode字符作为utf8从文件中回显

Bash 将unicode字符作为utf8从文件中回显,bash,macos,shell,unicode,Bash,Macos,Shell,Unicode,当我在终端中运行echo\U0041时,我得到一个 但是,当我从文件中运行echo\U0041时,请说example.sh,然后运行它 bash./example.sh或 sh./example.sh 我得到了文本\U0041 为什么??如何从文件中回显/打印A 更新: $SHELL-version->zsh 5.8 x86_64-apple-darwin20.0 我使用brew将bash升级到bash-5.1。 当我从文件中运行echo$'\u0041'时,我确实看到 我现在的问题是,当我似乎

当我在终端中运行echo\U0041时,我得到一个

但是,当我从文件中运行echo\U0041时,请说example.sh,然后运行它

bash./example.sh或 sh./example.sh

我得到了文本\U0041

为什么??如何从文件中回显/打印A

更新:


$SHELL-version->zsh 5.8 x86_64-apple-darwin20.0 我使用brew将bash升级到bash-5.1。 当我从文件中运行echo$'\u0041'时,我确实看到 我现在的问题是,当我似乎只能用单引号打印uf8,但变量需要双引号时,如何使十六进制代码成为变量

HEX='0041'
echo $"\u$HEX"

打印:\u0041

echo$'\u0041'打印一个英寸$自Bash 2.0以来一直可用。看起来您可能正在运行Bash 3.2中的脚本和更新的交互式shell。

您正在终端中使用zsh作为shell。它的echo版本理解\uxxx转义。如果使用echo-e或启用xdg_echo shell选项,bash的现代版本中内置的echo也是如此,但Mac OS附带的古老版本太旧,无法安装它。

我在这方面得到了一些帮助,但我的问题的完整解决方案是:

使用自制brew更新bash安装bash 在文件中使用echo-e或printf。 使用bash而不是sh运行。
那是哪个版本的Bash?Interactive Bash 5.1.4刚刚打印\U0041。我正在运行一台新的2020 mac,在互动终端上使用Bash-3.2而不是zsh?在你的互动SHELL中,$SHELL版本报告了什么?zsh 5.8 x86_64-apple-darwin20.0我也在尝试记录一个变量echo$\u$hex这可能吗?更新了上面的问题。
HEX='0041'
echo -e "\u$HEX"
$ bash ./example.sh
A