The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Bash recursive scripting James McMurray Shell Programming and Scripting 8 2 Weeks Ago 04:19 PM
Log FILES in BASH scripting jackdaw Shell Programming and Scripting 2 12-05-2007 01:25 PM
Bash shell Scripting help keyvan Shell Programming and Scripting 0 05-15-2007 03:36 PM
Help!! bash shell scripting.. Fr0z3n999 Shell Programming and Scripting 1 12-07-2006 01:08 PM
bash shell scripting azazalis Shell Programming and Scripting 4 07-11-2006 12:22 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 05-23-2007
Registered User
 

Join Date: May 2007
Posts: 14
Bash Scripting

Hello there peeps:

There is a little piece of bash shell scripting problem i have, which i was hoping you could help me with.

Code:
#!/bin/bash

stored_word()
{
case $(( $$ % 8  )) in
        0 ) echo "energy";;
        1 ) echo "touch";;
        2 ) echo "climbing";;
        3 ) echo "declare";;
        4 ) echo "marry";;
        5 ) echo "relax";;
        6 ) echo "bugs";;
        7 ) echo "inaccessible"
        #8 ) echo "country" ;;
        #9 ) echo "folder" ;;
        #10 ) echo "advertisement" ;;
        #11 ) echo "heading" ;;
        #12 ) echo "distasteful" ;;
        #13 ) echo "fashioned" ;;
        #14 ) echo "variation" ;;
        #15 ) echo "individual"

  esac
}
The code is suppose to generate a random word and insert it here:

Code:
        word=$(stored_word)
        letters=$(echo $word | wc -c)
        letters=$(( $letters - 1 ))
        template="$(echo $word | tr '[a-z A-Z 0-9]' '.')"
        remaining=$letters
the rest of the script i havent bothered pasting here, but i will if you guys will need to have a look at it.

Simply what i am trying to achieve is, for the function stored_word to generate a random word and then insert it into $word, which dose. then the 2nd piece of code, mixes it all up. The main problem is they are in the same script and need to be in 2 different script. How can i achieve that, without using sed or awk?

Keyvan
Reply With Quote
Forum Sponsor
  #2  
Old 05-23-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Code:
        . stored_word_script
        word=$(stored_word)
        letters=$(echo $word | wc -c)
        letters=$(( $letters - 1 ))
        template="$(echo $word | tr '[a-z A-Z 0-9]' '.')"
        remaining=$letters
Reply With Quote
  #3  
Old 05-23-2007
Registered User
 

Join Date: May 2007
Posts: 14
Quote:
Originally Posted by anbu23
Code:
        . stored_word_script
        word=$(stored_word)
        letters=$(echo $word | wc -c)
        letters=$(( $letters - 1 ))
        template="$(echo $word | tr '[a-z A-Z 0-9]' '.')"
        remaining=$letters
when the script is run, it keeps on running on the same word over and over again, instead of taking a new one and placing it in $word. is there any way of cleaning a Variable?

Keyvan
Reply With Quote
  #4  
Old 05-23-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Quote:
Originally Posted by keyvan
when the script is run, it keeps on running on the same word over and over again, instead of taking a new one and placing it in $word. is there any way of cleaning a Variable?

Keyvan
Use RANDOM instead of $$
Code:
case $(( $RANDOM % 8  )) in
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:38 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0