THank you for the replies! Please bear with me as I am obviously very new to unix and scripting.
Dave Miller:
Can you break this down for me?
read answer
ans=`cat $answer"N" | cut -c1-1 | tr "y" "Y"`
if [ $ans = "Y" ]
1. since it says read answer should the $ be answer instead of ans?
2. I dont understand this syntax: ans=`cat $answer"N" | cut -c1-1 | tr "y" "Y"`
why cat $answer"N"
cut portion I know means cut the first colum of the answer so the first letter what is the -1
tr I know mean so change so is that saying if the user puts a lower case y change it an uppercase?
denn - is the reason you prefer case is because there are multiple answers and even lower case, uppercase answers etc?
you was originally going to accept
y|Y|yes) for user input, so users being users, you've really no
idea what they'll type, just for kicks or to give you a hard time.
all the possible options they could use:
yes
YES
YEs
yES
yeS
YeS
yEs
When i give users a choice, I want either a definate positive or a negative,
anthing else is considered invalid and they'll be reasked until they give a proper response.
This is my suggestion:
Note: I commented out your
/usr/home/myhome/script.ksh
to test.
It's my habit, to not have the result of any calculation to use the source variable as the destination variable. That's why I used ans instead of answer.
To break it down:
ans=`cat $answer"N" | cut -c1-1 | tr "y" "Y"`
This is a three part process, the result of which becomes ans.
Part 1 actually has an error. It should be echo, not cat. It adds an 'N' to the end of whatever reply was supplied, thereby creating a default should the user hit enter without typing anything. The next step takes the first character and ignores the rest. The final step turns a lowercase 'y' into a capital 'Y'.
Then the if statement looks for a capitol 'Y'. Anything else, is the same as 'N'.
Hey everyone, just now joined because I didn't want to go onto Ubuntu forums and start asking about how to write shell scripts. Seems like this is a pretty active forum for exactly what I need.
I'm trying to modify a shell script I found online, the end goal is to have it find all files in the... (9 Replies)
Hello everybody,
I use `case' quite a lot but , excellent as it is , it only gives one
final result ; can anyone suggest a way whereas , say long
lists of choices are given and I , or a user could select either one
two or any number of results to be echoed .
many thanks in... (3 Replies)
I have a text file in this format
Some lines....
Question no: 1
The question?
A. Answer 1
B. Answer 2
C. Answer 3
D. Answer 4
Answer:B
Some lines....
Question no: 2
The question? (choose 2) (10 Replies)
Hi,
I am new in perl.
I am running a perl installation script, its asking for paths and so many inputs.
Can we provide that info by any file.
so i can avoid the interactive installation. (2 Replies)
Hello,
I need assistance with creating a shell script to generate SSL Certificate Requests on remote hosts. Below is my stab at this, but I cannot figure out how to pass the requested arguments into the openssl command correctly. I have a major problem with redirecting the "answers" into the... (2 Replies)
a) Total number of words in the file.
b) Total number of different words in the file.
How can I use the translate and/or unique commands to accomplish this (4 Replies)
All,
I have a list of over 400 users that need certain directories created. These will be created in /users/$username on a system and I need a directory called chess under these directories that I create.
Instead of me manually adding each one (mkdir /users/user1, mkdir /users/user1/chess)... (1 Reply)