Skip to content
Advertisement

Can someone help me to translate this line of code for bash shell?

I have been struggling to understand this line of code, could someone helpe me ?

for what I understood the od means will convert the outout for octal format, -An I think it means input base which is no address but why ? and the -N is the length

if someone could help to translate this while sintax I would appreciate

n=$((`od -An -N1 -i /dev/random` %100 ))

Advertisement

Answer

od -An -N1 -i /dev/random takes one byte (-N1) of input from /dev/random, treats it as a signed integer value (-i) and uses no address base (-An) (this is done to disable the header line od usually outputs). Running just this will give you a random number between 0 and 255.

Putting this command in backticks “`” places od’s output into the commandline.

$((x % y)) calculates x modulo y, where x is od’s output and y is 100 in your example.

Finally, the result is placed in the variable n which you can access by using e.g. echo $n

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement