02-28-2012
passing letters from an array into a string for string comparison
attempting the hangman program. This was an optional assignment from the professor. I have completed the logical coding, debugging now.
##I have an array $wordString[] that initializes to a string of dashes
##reflecting the number of letters in $theWord
##every time the user enters a (valid) letter this function is called and $letter is passed to it as $1
function updateWordString()
{
for ((x=1;x <= $numberOfLettersInTheWord;x++))
do
currentLetter=$(echo $theWord|head -c $x|tail -c 1)
if [ "$1" == "$currentLetter" ]
then
wordString[$x]="$currentLetter"
fi
done
}
##The problem now is that i have an array that look like "f o o b a r"
##So when i want to test in the following function if the user has completed
## the word, in essence its testing if "foobar" == "f o o b a r"
function isGameOver()
{
if [ "$theWord" == "${wordString[*]}" ]
then
return 2
fi
}
touro nyc, msis616 Prof Robinson
Thanks
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi all,
I have a variable, on some machines it is '1024', which is fine, but on others it is '1024Mb' etc. I need this variable to simply be '1024', does anyone know how I could ensure this is always the case? Perhaps a command to remove any letters/characters that aren't integers if there is... (3 Replies)
Discussion started by: hodges
3 Replies
2. Shell Programming and Scripting
Hello experts,
(tcsh shell)
Quite new to shell scripting...
I have got a file with a single word on each line. Want to be able to make a comparison such that i can read pairs of words that are ROT13 to each other. Also, i would like to print the pairs to another file.
Any help... (5 Replies)
Discussion started by: Jatsui
5 Replies
3. UNIX for Dummies Questions & Answers
Hi Guys
i need to write a script to check the file structure
I have added the the file headers in the configuration file and execute the file at the start of the script.
Now the function
checkFileStructure()
{
echo "Inside the function"
filetocheck=$1
fileheader=$2
if ]
then... (1 Reply)
Discussion started by: Swapna173
1 Replies
4. Shell Programming and Scripting
Is there a way to compare the permission string of two files and output the string if they match?
For ex:
-rw-r--r-- 1 user newuser 0 2009-03-12 16:45 file2
-rw-r--r-- 1 user newuser 0 2009-03-12 16:46 fileone
output:
-rw-r--r--
If they don't match output will be just... (3 Replies)
Discussion started by: squardius
3 Replies
5. Shell Programming and Scripting
#!/bin/sh
PRINTF=/usr/bin/printf
MACHINE_NAME=`uname -n`
TIME=`date +"%H"`
$PRINTF "Welcome to $MACHINE_NAME. What is your name?\n"
read NAME
if ; then
$PRINTF "Good morning $NAME, how are you?\n"
elif ; then
$PRINTF "Good afternoon $NAME, how are you?\n"
else
$PRINTF "Good... (2 Replies)
Discussion started by: ikeQ
2 Replies
6. Shell Programming and Scripting
continuing from my previous post, whose link is given below as a reference
https://www.unix.com/shell-programming-scripting/171076-shell-scripting.html#post302573569
consider there is create table commands in a file for eg:
CREATE TABLE `Blahblahblah` (
`id` int(11) NOT NULL... (2 Replies)
Discussion started by: vivek d r
2 Replies
7. Shell Programming and Scripting
I have an for loop that reads the following file
cat param.cfg
val1:env1:opt1
val2:env2:opt2
val3:env3:opt3
val4:env4:opt4
.
.
The for loop extracts the each line of the file so that at any one point, the value of i is
val1:env1:opt1 etc...
I would like to extract each... (19 Replies)
Discussion started by: goddevil
19 Replies
8. Shell Programming and Scripting
Hi Experts,
I am finding difficulty to get exact match:
file
OPERATING_SYSTEM=HP-UX
LOOPBACK_ADDRESS=127.0.0.1
INTERFACE_NAME="lan3"
IP_ADDRESS="10.53.52.241"
SUBNET_MASK="255.255.255.192"
BROADCAST_ADDRESS=""
INTERFACE_STATE=""
DHCP_ENABLE=0
INTERFACE_NAME="lan3:1"... (6 Replies)
Discussion started by: rveri
6 Replies
9. Shell Programming and Scripting
I have the logic below to look up for matches within the columns between the two files with awk.
In the if statement is where the string comparison is attempted with ==
The issue seems to be with the operands, as
1. when " '${SECTOR}' " -- double quote followed by single quote -- awk matches... (1 Reply)
Discussion started by: deadyetagain
1 Replies
10. UNIX for Beginners Questions & Answers
I will start with an example of what I'm trying to do and then describe how I am approaching the issue.
File
PS028,005
Lexeme HRS # M #
PhraseType 1(1:1) 7(7)
PhraseLab 501 503
ClauseType ZYq0
PS028,005
Lexeme W # L> # BNH # M #... (17 Replies)
Discussion started by: jvoot
17 Replies
LEARN ABOUT DEBIAN
yodlletter
yodlletter(7) Your Own Document Language yodlletter(7)
NAME
yodlletter - Yodl's `letter' document type
SYNOPSIS
letter(language)(date)(subject)(opening)(salutation)(author)
The letter document type was implemented to write LaTeX letters.
DESCRIPTION
The letter document type was specifically implemented to write LaTeX letters, using LaTeX's brief.cls document class. It is available only
for the LaTeX (yodl2latex(1)) converter.
This manual page briefly describes Yodl's letter document type. This document type is specific enough that it warrants a separate man-
page.
letter documents do not allow you to use the `standard' sectioning commands (e.g., sect() and subsect()). You can, however, use macros
that are normally used within such sections, such as description(), itemization(), bf() or em().
Several specific macros, to be used in the preamble, are available for the letter document type. They are:
o AfourEnlarged(): Enlarges the usable height of A4 paper by 2 cm.: the top margin is reduced by 2 cm.
o letteraddenda(type)(value): Adds an addendum at the end of a letter. type should be bijlagen (i.e., appendices), cc or ps. Use nl()
within the value section if multiple addenda of a certain type are used.
o letteradmin(yourdate)(yourref): Puts yourletterfrom and yourreference elements in the letter. If left empty, two dashes are
inserted.
o letterfootitem(name)(value): Puts a footer at the bottom of letter-pages. Up to three will usually fit. For example,
o letterreplyto(name)(address)(zip city): Defines the `reply to' address.
o letterto(element): Adds element as an additional line to the address of the addressee. Use one element for each line of the
addressee's address. Up to five lines will usually fit. A sixth line may be squeezed in, if necessary.
The letter) macro itself requires the following arguments:
o language: select english, dutch, or another language supported by the babel.sty style;
o date: the letter's date. Use your own date-convention. The text specified here will be used as the letter's date;
o subject: a short indication as to why you wrote the letter
o opening: the letter's opening, e.g., Dear Linus,;
o salutation: the letter's closing phrase, e.g., Kind regards,;
o author: the name of the letter's author. nl() macros can be used here, but the brief class will also restrict the width of the
author-lines by itself.
SEE ALSO
latex(1), yodlstriproff(1), yodl(1), yodlbuiltins(7), yodlconverters(1), yodlletter(7), yodlmacros(7), yodlmanpage(7), yodlpost(1),
yodlverbinsert(1).
BUGS
-
AUTHOR
Frank B. Brokken (f.b.brokken@rug.nl),
yodl_3.00.0.tar.gz 1996-2010 yodlletter(7)