ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Location: Rome, Italy ; Novi Sad, Srbija; Brisbane, Australia
Distribution: Ubuntu / ITOS2008
Posts: 1,207
Rep:
bash random function
I want to write a simple bash script that, when executed, will pick a random of 5 colors and start a aterm with that color.
So far i have just defined the vars:
RED="aterm -tint red"
GREEN="aterm -tint green"
and so on for every tint color, you get the point.
Now is there a random function that i can use, that will choose one of the variables and execute it? I know something like this exists in Perl, but is there a easy way in bash?
Thank you.
-NSKL
,----
| Shell Variables
| The following variables are set by the shell:
|
| [. . .]
|
| RANDOM Each time this parameter is referenced, a random
| integer between 0 and 32767 is generated. The
| sequence of random numbers may be initialized by
| assigning a value to RANDOM. If RANDOM is unset,
| it loses its special properties, even if it is sub-
| sequently reset.
`----
Location: Rome, Italy ; Novi Sad, Srbija; Brisbane, Australia
Distribution: Ubuntu / ITOS2008
Posts: 1,207
Original Poster
Rep:
Thanks for help, but i never read anything about bash scriping, just looked at some scripts and tried to figure out how it works, which is pretty much like any programming lang, but im still very newbie...
So, i have defined my vars:
I like unspawn's better. I didn't know about the 0:1 thang.
edit::
the 0:1 thang just selects the first character of the
random number string generated by $RANDOM --I had to
go read about it in the manpage-- whereas the %=
model generates a random number in the range of
posssible array elements. Take yer pick.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.