The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 11 02-02-2009 12:07 PM
Log FILES in BASH scripting jackdaw Shell Programming and Scripting 2 12-05-2007 04:25 PM
Bash shell Scripting help keyvan Shell Programming and Scripting 0 05-15-2007 07:36 PM
Help!! bash shell scripting.. Fr0z3n999 Shell Programming and Scripting 1 12-07-2006 04:08 PM
bash shell scripting azazalis Shell Programming and Scripting 4 07-11-2006 04:22 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-23-2007
keyvan keyvan is offline
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
  #2 (permalink)  
Old 05-23-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
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
  #3 (permalink)  
Old 05-23-2007
keyvan keyvan is offline
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
  #4 (permalink)  
Old 05-23-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:15 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0