Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Simple conditional yields too many responses Post 303030476 by rbatte1 on Monday 11th of February 2019 11:27:26 AM
Old 02-11-2019
Can I presume that if you enter hawk then the output you get is:-
Code:
~/bin$ bird
Enter name of a bird   hawk
That is not a bird.
That is not a bird.
Yes, that is a bird.

You code is doing what you are asking it to, but the issue (I presume) is a logical one.

You are checking if your input matches each of the items in turn, but you display the message every time. It would be better to define a flag/variable showing a failure before your loop then set the flag to a success within the loop if you meet the criteria. Then after the loop completes, you can display a message based on the flag.

Does that make sense? Sorry if it rather wordy.
Post your thoughts/next attempts and we can help with adjustments.


Kind regards,
Robin
This User Gave Thanks to rbatte1 For This Post:
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

ping to machine and count responses

if i wanted to ping all the machines in a given directory (/etc/hosts) and return a total count of responses how would i go about scripting that? complete newbie...so be gentle if ; then //$1 = /etc/hosts cd "$1" //this puts me into the directory i need...but how do i send ... (2 Replies)
Discussion started by: trostycp
2 Replies

2. Shell Programming and Scripting

How to automate responses

I would have searched for this but I couldn't really think of what to use for the search text... I've got a situation where I need to automate responses to an executable when running it from a script so that it can be made into a job the operators don't have to interact with. When I run it... (2 Replies)
Discussion started by: djp
2 Replies

3. Linux

How do I capture responses from the chat command?

Unfortunately googling the word 'chat' gives you zebedee billion responses that relate to everything and few of them refer to the linux chat command. I've read the man page and found a couple of examples but can't see how to do this. I want to query the modem for it's manufacturer, product id... (8 Replies)
Discussion started by: Bashingaway
8 Replies

4. Shell Programming and Scripting

Using AWK to Calculate Correct Responses

Hello, I am trying to count how many times a subject makes a correct switch or a correct stay response in a simple task. I have data on which condition they were in (here, labeled "IMAGINE" and "RECALL"), as well as whether they made a left or right button response, and whether the outcome was... (5 Replies)
Discussion started by: Jahn
5 Replies

5. Shell Programming and Scripting

Simple awk conditional one-liner

Hello, I'm looking for an awk one-liner that prints the first two data fields, then contains a conditional where if $3>$4, it prints $3-$4. Otherwise, it prints $3. Example: Data file: 123,456,999,888 333,222,444,555 654,543,345,888 444,777,333,111 Output: 123,456,111 333,222,444... (2 Replies)
Discussion started by: palex
2 Replies

6. Infrastructure Monitoring

SNMP responses failing under high system load

Greetings, I've got a Zenoss v2.5 server monitoring a large video encoding farm. Needless to say, these systems are under high bandwidth and CPU utilization the majority of the time. What I'm running into is that, occasionally, these systems will fail to respond to a standard SNMP request,... (1 Reply)
Discussion started by: Karunamon
1 Replies

7. IP Networking

DNS: Dig returns different responses...

Hey everyone, Okay, so I've been having some fun with the dig command, and wanted to dig my old school. Two questions came up from this. So I: dig @8.8.8.8 +recurse njcu.edu ANY and the result is about 8 records, including the SOA record. One of them is this weird TXT record, and the other is... (1 Reply)
Discussion started by: Lost in Cyberia
1 Replies

8. UNIX for Dummies Questions & Answers

Cp via NFS vs. scp yields unexpected difference

I have two Linux machines, Linux1 and Linux2. They both have two NFS mounts. We'll call them /scratch1 and /scratch2. And they both reside on the same NetApp filer. If I copy a 512Mb file from /scratch1 to /scratch2 while logged on Linux1 it takes 40s. However if I scp this file from... (1 Reply)
Discussion started by: crimso
1 Replies

9. Shell Programming and Scripting

Searching a file - and assigning responses to variables (or something)

So first: Sorry if the title is confusing... I have a script I'm writing with a file with several names in it (some other info - but it's not really pertinent...) - I want to be allow the user to delete certain records, but I ran into a problem I'm not sure how to go about fixing. If I were... (6 Replies)
Discussion started by: sabster
6 Replies
PARSE_INI_FILE(3)							 1							 PARSE_INI_FILE(3)

parse_ini_file - Parse a configuration file

SYNOPSIS
array parse_ini_file (string $filename, [bool $process_sections = false], [int $scanner_mode = INI_SCANNER_NORMAL]) DESCRIPTION
parse_ini_file(3) loads in the ini file specified in $filename, and returns the settings in it in an associative array. The structure of the ini file is the same as the php.ini's. PARAMETERS
o $filename - The filename of the ini file being parsed. o $process_sections - By setting the $process_sections parameter to TRUE, you get a multidimensional array, with the section names and settings included. The default for $process_sections is FALSE o $scanner_mode - Can either be INI_SCANNER_NORMAL (default) or INI_SCANNER_RAW. If INI_SCANNER_RAW is supplied, then option values will not be parsed. As of PHP 5.6.1 can also be specified as INI_SCANNER_TYPED. In this mode boolean, null and integer types are preserved when possible. String values "true", "on" and "yes" are converted to TRUE. "false", "off", "no" and "none" are considered FALSE. "null" is converted to NULL in typed mode. Also, all numeric strings are converted to integer type if it is possible. RETURN VALUES
The settings are returned as an associative array on success, and FALSE on failure. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 7.0.0 | | | | | | | Hash marks ( #) are no longer recognized as com- | | | ments. | | | | | 5.6.1 | | | | | | | Added new INI_SCANNER_TYPED mode. | | | | | 5.3.0 | | | | | | | Added optional $scanner_mode parameter. Single | | | quotes may now be used around variable assign- | | | ments. Hash marks ( #) should no longer be used | | | as comments and will throw a deprecation warning | | | if used. | | | | | 5.2.7 | | | | | | | On syntax error this function will return FALSE | | | rather than an empty array. | | | | | 5.2.4 | | | | | | | Keys and section names consisting of numbers are | | | now evaluated as PHP integers thus numbers start- | | | ing by 0 are evaluated as octals and numbers | | | starting by 0x are evaluated as hexadecimals. | | | | | 5.0.0 | | | | | | | Values enclosed in double quotes can contain new | | | lines. | | | | | 4.2.1 | | | | | | | This function is now affected by safe mode and | | | open_basedir. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 Contents of sample.ini ; This is a sample configuration file ; Comments start with ';', as in php.ini [first_section] one = 1 five = 5 animal = BIRD [second_section] path = "/usr/local/bin" URL = "http://www.example.com/~username" [third_section] phpversion[] = "5.0" phpversion[] = "5.1" phpversion[] = "5.2" phpversion[] = "5.3" urls[svn] = "http://svn.php.net" urls[git] = "http://git.php.net" Example #2 parse_ini_file(3) example Constants may also be parsed in the ini file so if you define a constant as an ini value before running parse_ini_file(3), it will be integrated into the results. Only ini values are evaluated. For example: <?php define('BIRD', 'Dodo bird'); // Parse without sections $ini_array = parse_ini_file("sample.ini"); print_r($ini_array); // Parse with sections $ini_array = parse_ini_file("sample.ini", true); print_r($ini_array); ?> The above example will output something similar to: Array ( [one] => 1 [five] => 5 [animal] => Dodo bird [path] => /usr/local/bin [URL] => http://www.example.com/~username [phpversion] => Array ( [0] => 5.0 [1] => 5.1 [2] => 5.2 [3] => 5.3 ) [urls] => Array ( [svn] => http://svn.php.net [git] => http://git.php.net ) ) Array ( [first_section] => Array ( [one] => 1 [five] => 5 [animal] => Dodo bird ) [second_section] => Array ( [path] => /usr/local/bin [URL] => http://www.example.com/~username ) [third_section] => Array ( [phpversion] => Array ( [0] => 5.0 [1] => 5.1 [2] => 5.2 [3] => 5.3 ) [urls] => Array ( [svn] => http://svn.php.net [git] => http://git.php.net ) ) ) Example #3 parse_ini_file(3) parsing a php.ini file <?php // A simple function used for comparing the results below function yesno($expression) { return($expression ? 'Yes' : 'No'); } // Get the path to php.ini using the php_ini_loaded_file() // function available as of PHP 5.2.4 $ini_path = php_ini_loaded_file(); // Parse php.ini $ini = parse_ini_file($ini_path); // Print and compare the values, note that using get_cfg_var() // will give the same results for parsed and loaded here echo '(parsed) magic_quotes_gpc = ' . yesno($ini['magic_quotes_gpc']) . PHP_EOL; echo '(loaded) magic_quotes_gpc = ' . yesno(get_cfg_var('magic_quotes_gpc')) . PHP_EOL; ?> The above example will output something similar to: (parsed) magic_quotes_gpc = Yes (loaded) magic_quotes_gpc = Yes NOTES
Note This function has nothing to do with the php.ini file. It is already processed by the time you run your script. This function can be used to read in your own application's configuration files. Note If a value in the ini file contains any non-alphanumeric characters it needs to be enclosed in double-quotes ("). Note There are reserved words which must not be used as keys for ini files. These include: null, yes, no, true, false, on, off, none. Values null, off, no and false result in "", and values on, yes and true result in "1", unless INI_SCANNER_TYPED mode is used (as of PHP 5.6.1). Characters ?{}|&~!()^" must not be used anywhere in the key and have a special meaning in the value. Note Entries without an equal sign are ignored. For example, "foo" is ignored whereas "bar =" is parsed and added with an empty value. For example, MySQL has a "no-auto-rehash" setting in my.cnf that does not take a value, so it is ignored. SEE ALSO
parse_ini_string(3). PHP Documentation Group PARSE_INI_FILE(3)
All times are GMT -4. The time now is 01:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy