Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$RANDOM in Bash doesn't work

Tags:

bash

random

Where could be the problem in this script?

#!bin/bash
NUMBER=$RANDOM
echo " The number is: $NUMBER"

when I start this script, it'll write this:

The number is:

(I am running Ubuntu 12.04)

like image 415
user1920217 Avatar asked Dec 20 '12 23:12

user1920217


People also ask

How do you generate a 3 digit random number in bash?

If you are using a linux system you can get a random number out of /dev/random or /dev/urandom. Be carefull /dev/random will block if there are not enough random numbers available. If you need speed over randomness use /dev/urandom. These "files" will be filled with random numbers generated by the operating system.

What is $_ in bash?

$_ (dollar underscore) is another special bash parameter and used to reference the absolute file name of the shell or bash script which is being executed as specified in the argument list. This bash parameter is also used to hold the name of mail file while checking emails.

What does $$ mean in bash?

Symbol: $$ The symbol $$ stores the PID of the current shell. For example: #! /bin/bash. echo $$ In my case, it printed out the value 2443.


1 Answers

Because you have an error in your shebang, it should be :

#!/bin/bash

(note the missing /)

like image 107
Gilles Quenot Avatar answered Oct 11 '22 15:10

Gilles Quenot