English 中文(简体)
缩略语
原标题:/bin/bash printf does not work with other LANG than C

我存在一个真正令人厌恶的问题,即使用印本制作插图。

我的言辞看着这一点。

rt=$(printf "%.3f" 13.234324245)

with the difference, that i compute the number 13.23... above. When i use /usr/bin/zsh that works great! Even /bin/sh can do it (but it cant do the if stuff...) The biggest problem ist that /bin/bash seems to does not understand printf or does have another formating way when i dont use LANG=C.

My LANG 可变现为<代码>de_AT.UTF-8,然后取出:

/path/to/script: Zeile 12: printf: 13.234324245: Ungültige Zahl.

因此,它简单地说,一面打印件的数量是无效的......

Do i need to run printf in a different way?

编辑:问题似乎是计算数字:

rt=$(printf "%.3f" $(echo "$res2 - $res1"|bc ))

如何用<条码>、而不是<条码>(<>>/代码>)来说明条码。

最佳回答
问题回答

Just do a $(LANG=Ctextf“%.3f” 13.234324245), only set LANG on this direct

这可能是一个局部问题——我认为德国语中德西马尔语的分离器是:<条码>,,而不是<条码>。 采用<代码>13,2343245作为您的价值。

您可使用其他<条码>:执行:无bu/用户/宾/印本:

% # LANG is ru_RU.UTF8, decimal separator is comma
% /usr/bin/printf %.3f 3.14
3,140
% /usr/bin/printf %.3f 3,14
/usr/bin/printf: 3,14: значение преобразовано не полностью
3,000
% LANG=C /usr/bin/printf %.3f 3,14
printf: 3,14: value not completely converted
3.00

采用<代码>zsh后印成文实施:

% printf %.3f 3.14
3,140
% printf %.3f 3,14
3,140




相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Bash usage of vi or emacs

From a programming standpoint, when you set the bash shell to use vi or emacs via set -o vi or set -o emacs What is actually going on here? I ve been reading a book where it claims the bash shell ...

Dynamically building a command in bash

I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...

Perform OR on two hash outputs of sha1sum

I want perform sha1sum file1 and sha1sum file2 and perform bitwise OR operation with them using bash. Output should be printable i.e 53a23bc2e24d039 ... (160 bit) How can I do this? I know echo $(( ...

Set screen-title from shellscript

Is it possible to set the Screen Title using a shell script? I thought about something like sending the key commands ctrl+A shift-A Name enter I searched for about an hour on how to emulate ...

热门标签