Sponsored Content
Top Forums Shell Programming and Scripting IF condition against a ARRAY in shell script Post 302416512 by frans on Monday 26th of April 2010 06:00:54 PM
Old 04-26-2010
Code:
#!/bin/bash
ARRAY=( a b c d e f )
read -p "Enter element : " K
FOUND=0
for E in ${ARRAY[@]}
do	[ "$K" = "$E" ] && FOUND=1
done
echo -n "$K "; ((FOUND)) && echo "found" || echo "not found"

I use a flag here but if you only have to perform an action if found then use following code
Code:
#!/bin/bash
ARRAY=( a b c d e f )
read -p "Enter element : " K
for E in ${ARRAY[@]}
do	if [ "$K" = "$E" ]
        then echo "$K found"
        fi
done

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

need help with test condition in shell script

I'm new to scripting and I need help with a bourn shell script. What i'm trying to do is a test condition where "if the time is within 2 hours, it's true" and so on. The time is in the following format DATE=`/bin/date +"%Y%m%d%H%S"` for example, 20060907152000. So, what the script first... (9 Replies)
Discussion started by: pieman8080
9 Replies

2. Shell Programming and Scripting

Help with shell script to check the condition.

:) Hi, I want to script for this scenerio, OSR Settings Scenario : We are looking to find all the *.a files from the following locations in the filesystem of a server. OSR Directories /etc /bin /usr/bin /usr/sbin /var/adm These *.a files should have the permissions on... (12 Replies)
Discussion started by: sakthilinux
12 Replies

3. AIX

if condition in AIX5.3-10 shell script

True if file exists and has been modified since it was last read. if then command else exit fi i am on AIX5.3-10. it does not understand -N any other way. i can use -ot (file1 is older than file2), but prefer -N if possible. (3 Replies)
Discussion started by: tjmannonline
3 Replies

4. Shell Programming and Scripting

An issue with condition statement in shell script

Hello forum members. please go through the below mentioned issue and let me know the right solution. I have to write a script which runs another script .the executable script take input parmeters.so iam writing the the script below . Sample Code:Begins #! /bin/ksh echo " enter... (2 Replies)
Discussion started by: rajkumar_g
2 Replies

5. Shell Programming and Scripting

Errors in if condition validations-Shell Script

Hello All, i am facing difficulty in validating the values, kindly help me in resolving the issue. Thanks a lot in advance. -Chandra Script:Test.sh #! /bin/sh # *************************************************************************** # Function to display help function usage()... (1 Reply)
Discussion started by: duddukuri
1 Replies

6. UNIX for Dummies Questions & Answers

While condition in shell script

while do if ;then read driverName else driverName="" fi done can anyone please explain what exactly is happening on 1st line...is it like the conditions being ORed...I have no clue about this. (4 Replies)
Discussion started by: rtagarra
4 Replies

7. Shell Programming and Scripting

Substring check in IF condition in shell script

I want to check if the string has the substring in IF condition then process... i tried below but not working if ]; then ............. field can be "reserved1" ....reservedn / fillspaces1 ... fillspacesn (4 Replies)
Discussion started by: greenworld123
4 Replies

8. Shell Programming and Scripting

Need Help to add Condition in Shell Script..

Hi Team, I m very new to shell scripting , i want to add following condition in my script . Can anybody help me. There are three port in My node "$port" port_A port_B port_C I Want to add following Conditions in my script. If Node is connected to port_A and port_B script... (10 Replies)
Discussion started by: Ganesh Mankar
10 Replies

9. Shell Programming and Scripting

If condition shell script beginner

Hi all I have the folloing process that needs checking often: ps -ef | grep ih bscsrtx 206 15901 0 11:28:10 pts/6 0:00 fih -r4 bscsrtx 218 15901 0 11:28:27 pts/6 0:01 aih bscsrtx 29763 15901 4 11:27:16 pts/6 0:59 rdh -prih root 429 27268 0 11:30:15 pts/td ... (13 Replies)
Discussion started by: fretagi
13 Replies

10. Shell Programming and Scripting

Pass C shell array to another C shell script(csh) and shell(sh)

Dear Friends, Please help me on this my script name is send.csh In this i have written the statement like this set args = ( city state country price ) I want to pass this array to another c shell called receiver.csh. and i want to use it in this c shell or how to pass to... (2 Replies)
Discussion started by: SA_Palani
2 Replies
Log::Report::Lexicon::PO(3pm)				User Contributed Perl Documentation			     Log::Report::Lexicon::PO(3pm)

NAME
Log::Report::Lexicon::PO - one translation definition DESCRIPTION
This module is administering one translation object. Sets of PO objects are kept in a POT file, implemented in Log::Report::Lexicon::POT. METHODS
Constructors Log::Report::Lexicon::PO->new(OPTIONS) -Option --Default automatic "" comment [] format [] fuzzy false msgid <required> msgid_plural undef msgstr "" or [] references [] automatic => PARAGRAPH Automatically added comments. See addAutomatic(). comment => PARAGRAPH Translator added comments. See addComment(). format => ARRAY-OF-PAIRS|HASH See format(). fuzzy => BOOLEAN The string is not yet translated, some smart guesses may have been made. See fuzzy(). msgid => STRING msgid_plural => STRING msgstr => STRING|ARRAY-OF-STRING The translations for the msgid. When msgid_plural is defined, then an ARRAY must be provided. references => STRING|ARRAY-OF-LOCATIONS The STRING is a blank separated list of LOCATIONS. LOCATIONs are of the form "filename:linenumber", for instance "lib/Foo.pm:42" See addReferences() Attributes $obj->addAutomatic(LIST|ARRAY|STRING) Add multiple lines to the translator's comment block. Returns an empty string if there are no comments. $obj->addComment(LIST|ARRAY|STRING) Add multiple lines to the translator's comment block. Returns an empty string if there are no comments. $obj->addFlags(STRING) Parse a "flags" line. $obj->addReferences(STRING|LIST|ARRAY) The STRING is a blank separated list of LOCATIONS. The LIST and ARRAY contain separate LOCATIONs. A LOCATION is of the form "filename:linenumber". Returns the internal HASH with references. $obj->automatic([LIST|ARRAY|STRING]) Returns a STRING which contains the cleaned paragraph of automatically added comments. If an argument is specified, it will replace the current comment. $obj->comment([LIST|ARRAY|STRING]) Returns a STRING which contains the cleaned paragraph of translator's comment. If an argument is specified, it will replace the current comment. $obj->format(LANGUAGE|PAIRS|ARRAY-OF-PAIRS|HASH) When one LANGUAGE is specified, it looks whether a "LANGUAGE-format" or "no-LANGUAGE-format" is present in the line of FLAGS. This will return 1 (true) in the first case, 0 (false) in the second case. It will return "undef" (also false) in case that both are not present. You can also specify PAIRS: the key is a language name, and the value is either 0, 1, or "undef". example: use of format() if($po->format('c')) ... unless($po->format('perl-brace')) ... if(defined $po->format('java')) ... $po->format(java => 1); # results in 'java-format' $po->format(java => 0); # results in 'no-java-format' $po->format(java => undef); # results in '' $obj->fuzzy([BOOLEAN]) Returns whether the translation needs human inspection. $obj->isActive Returns whether the translation has any references, or is the header. $obj->msgid Returns the actual msgid, which cannot be "undef". $obj->msgstr([INDEX, [STRING]]) With a STRING, a new translation will be set. Without STRING, a lookup will take place. When no plural is defined, use INDEX 0 $obj->plural([STRING]) Returns the actual msgid_plural, which can be "undef". $obj->references([STRING|LIST|ARRAY]) Returns an unsorted list of LOCATIONS. When options are specified, then those will be used to replace all currently defined references. Returns the unsorted LIST of references. $obj->removeReferencesTo(FILENAME) Remove all the references to the indicate FILENAME from the list. Returns the number of refs left. Parsing Log::Report::Lexicon::PO->fromText(STRING, [WHERE]) Parse the STRING into a new PO object. The WHERE string should explain the location of the STRING, to be used in error messages. $obj->toString(OPTIONS) Format the object into a multi-lined string. -Option --Default nr_plurals undef nr_plurals => INTEGER If the number of plurals is specified, then the plural translation list can be checked for the correct length. Otherwise, no smart behavior is attempted. $obj->unused The message-id has no references anymore and no translations. SEE ALSO
This module is part of Log-Report distribution version 0.94, built on August 23, 2011. Website: http://perl.overmeer.net/log-report/ LICENSE
Copyrights 2007-2011 by Mark Overmeer. For other contributors see ChangeLog. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html perl v5.14.2 2012-03-02 Log::Report::Lexicon::PO(3pm)
All times are GMT -4. The time now is 01:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy