- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Random Variable at Shell Script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2002 05:16 AM
07-26-2002 05:16 AM
Random Variable at Shell Script
Hi All,
I need to do the following:
var1=
echo $var1 > file.txt
sleep 30;
var2=cat file.txt
If var1 = var 2 the
....
The problem is : How to create a random variable using shell only ( bash, korn )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2002 05:18 AM
07-26-2002 05:18 AM
Re: Random Variable at Shell Script
# man random
DESCRIPTION
The random() and srandom() functions are random-number generators that have virtually the same calling sequence and initialization properties as the rand() and srand() functions, but produce sequences that are more random
Cheryl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2002 05:21 AM
07-26-2002 05:21 AM
Re: Random Variable at Shell Script
Search the forums and you will find more.
Search from the left, enter random in the search box and click the option for Community Forum.
Cheryl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2002 05:23 AM
07-26-2002 05:23 AM
Re: Random Variable at Shell Script
Is there a way to run this random cmd using only shell script ? ( not C or PERL )
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2002 05:29 AM
07-26-2002 05:29 AM
Re: Random Variable at Shell Script
There is actually an environment variable named RANDOM which suits your need.
Try several of these to see for yourself
# echo $RANDOM
# echo $RANDOM # diff. output
# ...
Hai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2002 07:51 AM
07-26-2002 07:51 AM
Re: Random Variable at Shell Script
RANDOM=$(date +%S)
MESS=$((RANDOM % 5))
case $MESS in
1) echo "Random number 1 generated";;
2) echo "Random number 2 generated";;
3) echo "Random number 3 generated";;
4) echo "Random number 4 generated";;
5) echo "Random number 5 generated";;
esac
The first "variable" RANDOM sets the "seed" (randomness if you like) based on the current date. The variable MESS is then chosen at random between 1 & 5.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2002 07:53 AM
07-26-2002 07:53 AM