The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

    • RT @BadAstronomer: And on top of it, this. IN THE MIDDLE OF A PANDEMIC. This is where anti-science takes us, folks. Right here. 2 hours ago
    • RT @isotopp: [Aquara Sensor] -> (zigbee) -> [zigbee2mqtt] -> -> [mqtt] -> (mosquitto) -> [mqtt] -> (python consumer) -> [http/influx] -> (i… 2 hours ago
    • RT @raoulbeunen: Zelfs in beschermd #Natura2000 gebied is de natuur niet veilig. In de uiterwaarden bij @Gem_Wageningen is het kruiden- en… 2 hours ago
    • RT @recursecenter: For the rest of 2020 we're running all of our batches online, which means that you can join RC from anywhere in the worl… 2 hours ago
    • RT @StevenGeurts: Ik vind er een zekere schoonheid in zitten dat het klimaat net zo duur blijkt te zijn als het overeind houden van een luc… 2 hours ago
  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,920 other followers

Archive for the ‘bash’ Category

David Korn Tells All – Slashdot

Posted by jpluimers on 2020/05/21

Almost 20 years old, but still a very nice read [Archive.is] David Korn Tells All – Slashdot.

Another funny story involving David Korn during the not-so open source times of Microsoft late last century: [WayBack] Korn Shell Story

–jeroen

Posted in *nix, *nix-tools, bash, bash, Development, History, Power User, Scripting, Software Development | Leave a Comment »

Bash Notes for Professionals book

Posted by jpluimers on 2020/05/12

For my reading list: Bash Notes for Professionals book

Download: [WayBack]  BashNotesForProfessionals.pdf

Via: [WayBack] Bash Notes for Professionals – a book compiled from Stack Overflow Documentation released under Creative Commons BY-SA  – ThisIsWhyICode – Google+

–jeroen

Posted in *nix, *nix-tools, bash, bash, Development, Power User, Scripting, Software Development | Leave a Comment »

bash – How to add a progress bar to a shell script? – Stack Overflow

Posted by jpluimers on 2020/03/17

From [WayBackbash – How to add a progress bar to a shell script? – Stack Overflow (thanks Mitch Haile!):

You can implement this by overwriting a line. Use \r to go back to the beginning of the line without writing \n to the terminal.

Write \n when you’re done to advance the line.

Use echo -ne to:

  1. not print \n and
  2. to recognize escape sequences like \r.

Here’s a demo:

echo -ne '#####                     (33%)\r'
sleep 1
echo -ne '#############             (66%)\r'
sleep 1
echo -ne '#######################   (100%)\r'
echo -ne '\n'

–jeroen

Posted in *nix, *nix-tools, bash, bash, Development, Power User, Scripting, Software Development | Leave a Comment »

linux – Bash: Command grouping (&&, ||, …) – Stack Overflow

Posted by jpluimers on 2020/02/18

Excellent answer at [WayBack] linux – Bash: Command grouping (&&, ||, …) – Stack Overflow by Charles Duffy:

Operator precedence for && and || is strictly left-to-right.

Thus:

pwd; (ls) || { cd .. && ls student/; }  && cd student || cd / && cd ;

…is equivalent to…

pwd; { { { (ls) || { cd .. && ls student/; }; } && cd student; } || cd /; } && cd ; }

…breaking that down graphically:

pwd; {                                      # 1
       {                                    # 2
         { (ls) ||                          # 3
                   { cd .. &&               # 4
                              ls student/;  # 5
                   };                       # 6
         } && cd student;                   # 7
       } || cd /;                           # 8
     } && cd ;                              # 9
  1. pwd happens unconditionally
  2. (Grouping only)
  3. ls happens (in a subshell) unconditionally.
  4. cd .. happens if (3) failed.
  5. ls student/ happens if (3) failed and (4) succeeded
  6. (Grouping only)
  7. cd student happens if either (3) succeeded or both (4) and (5) succeeded.
  8. cd / happens if either [both (3) and one of (4) or (5) failed], or [(7) failed].
  9. cd happens if (7) occurred and succeeded, or (7) occurred and succeeded.

Using explicit grouping operators is wise to avoid confusing yourself. Avoiding writing code as hard to read as this is even wiser.

–jeroen

Posted in *nix, *nix-tools, bash, bash, Development, Power User, Scripting, Software Development | Leave a Comment »

bash: converting numbers to human readable SI or IEC units

Posted by jpluimers on 2019/12/03

Many unix tools that report sizes in bytes can convert them to either IEC or SI readable formats.

For github.com/jpluimers/btrfs-du/blob/master/btrfs-du I wrote about last week, I also wanted that kind of behaviour. So I did some research and came up with the code and test cases below.

Note that depending on the bitness of your system, bash integer numeric values are limited in size; see [WayBack] What is the maximum value of a numeric bash shell variable? – Super User.

So I wrote a small bash script for that too, which needed also gave me the opportunity to show how a  perpetual while loop as explained by [WayBack] bash – “while :” vs. “while true” – Stack Overflow.

Two things that always bite me with these short scripts are expressions (done through [WayBack]Arithmetic Expansion) and comparisons (through[WayBack] Other Comparison Operators).

The IEC suffixes contain one extra i to indicate binary and – next to the ISO notation that were already ISO defined – made it into the ISO 80000 standard since 2008. Here is a comparison list from [WayBackBinary prefix – Wikipedia:

Prefixes for multiples of
bits (bit) or bytes (B)
Decimal
Value SI
1000 k kilo
10002 M mega
10003 G giga
10004 T tera
10005 P peta
10006 E exa
10007 Z zetta
10008 Y yotta
Binary
Value IEC JEDEC
1024 Ki kibi K kilo
10242 Mi mebi M mega
10243 Gi gibi G giga
10244 Ti tebi
10245 Pi pebi
10246 Ei exbi
10247 Zi zebi
10248 Yi yobi

Most tools nowadays default to binary IEC suffixes for byte sizes, though disk manufacturers still use SI suffixes because, well then they appear bigger but aren’t. Just for comparison, look at the numbers from [WayBack] File size – Wikipedia and [WayBack] IEC and SI Size Notations – AN!Wiki where I got the test cases from:

Read the rest of this entry »

Posted in *nix, *nix-tools, bash, bash, Development, Power User, Scripting, Software Development | Leave a Comment »

 
%d bloggers like this: