[QUOTE=andrew.comly;5538519]I am learning bash programming language. I would like to better understand the following command in line 6 of Example 9-17 Pseudorandom numbers, using awk (
http://www.tldp.org/LDP/abs/html/randomvar.html).
Code:
srand(); print rand()
That
is not the authentic line from your example code! It should be
Code:
AWKSCRIPT=' { srand(); print rand() } '
and has a different meaning than that of a command to execute on a command-line.
Above, in the introductory comment, it is written
Quote:
# Uses the awk rand() function.
|
To the variable
AWKSCRIPT, is assigned a line of text
' { srand(); print rand() } ' which comprises 2 commands that awk will execute. It does not make sense to have bash execute awk-scripts.
In the previous examples, notably before very first one on the page, the internal Bash function $RANDOM is mentioned. It should now be obvious which command needs awk and which one will run on the bash command-line.
This mystery sorted out, you can lookup both ways to create random numbers in the man-pages.
man awk (then search for rand() )
man bash (then search for RANDOM)