Below is the javascript code which produces output after it’s successful execution to something like this 542432b384789
<code>Math.random().toString(16).substr(2, 32)
</code>
<code>Math.random().toString(16).substr(2, 32)
</code>
Math.random().toString(16).substr(2, 32)
How can reproduce this operation in the linux bash script?
Tried below code
<code>#!/bin/bash
# Generate a random number between 0 and 1
RANDOM_NUMBER=$(Math.random())
# Convert the random number to a hexadecimal string
HEX_STRING=$(RANDOM_NUMBER.toString(16))
# Remove the first two characters of the hexadecimal string
RANDOM_STRING=$(HEX_STRING.substr(2, 32))
# Print the random string
echo $RANDOM_STRING
</code>
<code>#!/bin/bash
# Generate a random number between 0 and 1
RANDOM_NUMBER=$(Math.random())
# Convert the random number to a hexadecimal string
HEX_STRING=$(RANDOM_NUMBER.toString(16))
# Remove the first two characters of the hexadecimal string
RANDOM_STRING=$(HEX_STRING.substr(2, 32))
# Print the random string
echo $RANDOM_STRING
</code>
#!/bin/bash
# Generate a random number between 0 and 1
RANDOM_NUMBER=$(Math.random())
# Convert the random number to a hexadecimal string
HEX_STRING=$(RANDOM_NUMBER.toString(16))
# Remove the first two characters of the hexadecimal string
RANDOM_STRING=$(HEX_STRING.substr(2, 32))
# Print the random string
echo $RANDOM_STRING
But it’s throwing below error messages.
<code>test-string.sh: command substitution: line 5: syntax error near unexpected token `)'
test-string.sh: command substitution: line 5: `Math.random())'
test-string.sh: command substitution: line 8: syntax error near unexpected token `16'
test-string.sh: command substitution: line 8: `RANDOM_NUMBER.toString(16))'
test-string.sh: command substitution: line 11: syntax error near unexpected token `2,'
test-string.sh: command substitution: line 11: `HEX_STRING.substr(2, 32))'
</code>
<code>test-string.sh: command substitution: line 5: syntax error near unexpected token `)'
test-string.sh: command substitution: line 5: `Math.random())'
test-string.sh: command substitution: line 8: syntax error near unexpected token `16'
test-string.sh: command substitution: line 8: `RANDOM_NUMBER.toString(16))'
test-string.sh: command substitution: line 11: syntax error near unexpected token `2,'
test-string.sh: command substitution: line 11: `HEX_STRING.substr(2, 32))'
</code>
test-string.sh: command substitution: line 5: syntax error near unexpected token `)'
test-string.sh: command substitution: line 5: `Math.random())'
test-string.sh: command substitution: line 8: syntax error near unexpected token `16'
test-string.sh: command substitution: line 8: `RANDOM_NUMBER.toString(16))'
test-string.sh: command substitution: line 11: syntax error near unexpected token `2,'
test-string.sh: command substitution: line 11: `HEX_STRING.substr(2, 32))'
How can we reproduce this javascript operation in the Linux bash script?