Flag | Usage |
---|---|
(none) | encode parameter into base64 format |
-d base64EncodedString --decode base64EncodedString |
decode base64EncodedString |
-w n --wrap=n |
wrap encoded lines after n characters (defaults to 76). Use 0 to disable line wrapping (i.e. output a giant single line) |
newline
to the expression to encode (like echo does) :
SGVsbG8gV29ybGQgIQo= SGVsbG8gV29ybGQgIQo=
round()
of the resultmodulo
...0 integer part only .50000000000000000000 20 decimals, as expected .50 only 2 decimals, as specified
8 / 3 = 2 9 / 3 = 3 10 / 3 = 3 11 / 3 = 3 12 / 3 = 4 13 / 3 = 4 14 / 3 = 4 15 / 3 = 5 16 / 3 = 5
01 / 2
= 0.5 → 0,0 * 2
= 0.0 → 0 12 * 1
= 2.0 → 2,2 / 2
= 1.0 → 1
Flag | Usage |
---|---|
-l --mathlib |
|
-q --quiet | do not print the welcome banner |
less -p "four special variables"
' bcName | Usage |
---|---|
scale=n | set the number of digits after the decimal point to n
echo 'scale=3; 1+1; 1/1' | bc
2 1.000 defaults to 0.
|
.
with a ,
: printf %0.f 3,141592654Trying to round numbers with printf :for i in 0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5; do printf "i : %s, round(i,0) : %.0f\n" "$i" "$i"; done | column -ti : 0.5, round(i,0) : 0 can't explain this i : 1.5, round(i,0) : 2 can't explain this i : 2.5, round(i,0) : 2 i : 3.5, round(i,0) : 4 i : 4.5, round(i,0) : 4 i : 5.5, round(i,0) : 6 i : 6.5, round(i,0) : 6 i : 7.5, round(i,0) : 8 i : 8.5, round(i,0) : 8 i : 9.5, round(i,0) : 10for i in 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1; do printf "i : %s, round(i,1) : %.1f, round(i,0) : %.0f\n" "$i" "$i" "$i"; done | column -ti : 0, round(i,1) : 0.0, round(i,0) : 0 i : 0.1, round(i,1) : 0.1, round(i,0) : 0 i : 0.2, round(i,1) : 0.2, round(i,0) : 0 i : 0.3, round(i,1) : 0.3, round(i,0) : 0 i : 0.4, round(i,1) : 0.4, round(i,0) : 0 i : 0.5, round(i,1) : 0.5, round(i,0) : 0 not rounded to 1 i : 0.6, round(i,1) : 0.6, round(i,0) : 1 i : 0.7, round(i,1) : 0.7, round(i,0) : 1 i : 0.8, round(i,1) : 0.8, round(i,0) : 1 i : 0.9, round(i,1) : 0.9, round(i,0) : 1 i : 1, round(i,1) : 1.0, round(i,0) : 1
for i in 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1; do simple=$(echo "$i/1" | bc); rounded=$(echo "($i+0.5)/1" | /usr/bin/bc); echo "$i $simple $rounded"; done | column -t0 0 0 0.1 .10000000000000000000 0 0.2 .20000000000000000000 0 0.3 .30000000000000000000 0 0.4 .40000000000000000000 0 0.5 .50000000000000000000 1 now rounded to 1 0.6 .60000000000000000000 1 0.7 .70000000000000000000 1 0.8 .80000000000000000000 1 0.9 .90000000000000000000 1 1 1.00000000000000000000 1
var=2.5; echo $var | awk '{print int($1+0.5)}' 3for i in {1000..1005}; do a=$(echo "$i/2" | /usr/bin/bc); b=$(echo "scale=1; $i/2" | /usr/bin/bc); c=$(echo "scale=1; (($i/2)+0.5)/1" | /usr/bin/bc); echo -e "$i/2=\t$a\t$b\t$c"; done1000/2= 500 500.0 500.5 1001/2= 500 500.5 501.0 1002/2= 501 501.0 501.5 1003/2= 501 501.5 502.0 1004/2= 502 502.0 502.5 1005/2= 502 502.5 503.0==> so far, I've found no "pure-bc" means to round to integer
To do so, use the ibase (input base) and obase (output base) bc options :
for
, while
, or until
loop, or from the nth enclosing loop, if n is specified (defaults to 1).for
loop :#!/usr/bin/env bash for i in {1..2}; do echo $i break echo 'this will never be executed' donedisplays :
1
for
loops :#!/usr/bin/env bash for i in {1..2}; do for j in {a..b}; do echo $i$j break echo 'this will never be executed' done donedisplays :
1a 2a
for
loops and break 2 :#!/usr/bin/env bash for i in {1..2}; do for j in {a..b}; do echo $i$j break 2 echo 'this will never be executed' done donedisplays :
1a
You definitely should have a look at pbzip2 :
alias bzip2='pbzip2' alias bunzip2='pbzip2 -d'
BEFORE -rw------- 1 bob users 0 May 23 1982 /tmp/testFile both files have the same date AFTER -rw------- 1 bob users 14 May 23 1982 /tmp/testFile.bz2 bzip2 is aliased to `pbzip2' we used pbzip2, which mimics bzip2 behavior
Flag | Usage |
---|---|
|
|
-k --keep | keep input files during compression or decompression |