Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Help with if else statement... Post 303046358 by AgentOrange on Saturday 2nd of May 2020 10:27:50 AM
Old 05-02-2020
Thank you for your response vbe :-)


so I have


Code:
#!/bin/bash
printf "checking for hidden modules: "
for mm in /sys/module/*; do 
   if test -d ${mm}/sections; then 
      MOD="$(basename ${mm})"; 
      lsmod | grep -E "^${MOD}" > /dev/null || printf "[found hidden module] \n${MOD}\n"; 
   fi;
done

which works as expected. Problem is that:
1) if it doesn't find any modules, i cant figure out with this particular command how to make it say [ok] insted of
[found hidden module]
diamorphine
2) if it doesnt find any modules, it doesn't return a new line. Which would be solved also if I could figure out 1) !


Moderator's Comments:
Mod Comment Please use code tags, for you code and data, thanks

Last edited by vbe; 05-02-2020 at 01:44 PM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If statement

Hi, I have a statement in shell script which i am writing below: if ] then ..... What is the meaning of -a option in files, meaning of the statement in the if condition ] means. Thanks (3 Replies)
Discussion started by: dreams5617
3 Replies

2. Shell Programming and Scripting

if statement

can someone please tell me what is wrong with the below. i'm trying to get a script to run if the content of a variable is either small letter y or capital letter Y. if then whatever fi (4 Replies)
Discussion started by: Terrible
4 Replies

3. Shell Programming and Scripting

statement

I want to write a program that would convert yard to feet and feet to yard. i.e 1 yard = 3 * feet Echo "enter a" read a expr a *3 The trick is that I want to give the user some options. After the conversion from yard to feet is done, I want to ask the user whether or not he/she wants to... (10 Replies)
Discussion started by: Ernst
10 Replies

4. Shell Programming and Scripting

If statement - How to write a null statement

In my ksh script, if the conditions of a if statement are true, then do nothing; otherwise, execute some commands. How do I write the "do nothing" statement in the following example? Example: if (( "$x"="1" && "$y"="a" && "$z"="happy" )) then do nothing else command command fi... (3 Replies)
Discussion started by: april
3 Replies

5. Shell Programming and Scripting

How is use sselect statement o/p in insert statement.

Hi All, I am using Unix ksh script. I need to insert values to a table using the o/p from a slelect statement. Can anybody Help! My script looks like tihs. ---`sqlplus -s username/password@SID << EOF set heading off set feedback off set pages 0 insert into ${TB_NAME}_D... (2 Replies)
Discussion started by: nkosaraju
2 Replies

6. UNIX for Dummies Questions & Answers

If statement (yes or no)

I have the program: #!/bin/ksh echo Please enter yes or no read n typeset -l n if ] then echo My name exit else echo delete my name fi Question: How can I make the program accept only the word "yes" or "no" otherwise it will ask the user to re-enter? Thanks! (7 Replies)
Discussion started by: bobo
7 Replies

7. Shell Programming and Scripting

If statement help

I'm trying to create a script that would allow me to identify the sucessful removal of a file. Here's what i put together so far, let me know if it's correct or not. FILE_NAME="cactus.dat" FILE_FIND='find / -name $FILE_NAME' if ;then echo "cactus.dat was not removed successfully" ... (3 Replies)
Discussion started by: sdpinoy
3 Replies

8. Shell Programming and Scripting

Statement

${PFILE}.backupfile Please tell me what the above statement means? (1 Reply)
Discussion started by: lg123
1 Replies

9. Shell Programming and Scripting

If statement

Hi, I have this code here. Its suppose to do something when certain condition is met, I'm pretty sure at least one of the condition will be meet somewhere in the loop but it always go to else part of the script. Is something wrong on this script? age_list=`tar -tvf /home/dir/$tarfile... (4 Replies)
Discussion started by: erin00
4 Replies

10. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies
Module::Info(3) 					User Contributed Perl Documentation					   Module::Info(3)

NAME
Module::Info - Information about Perl modules SYNOPSIS
use Module::Info; my $mod = Module::Info->new_from_file('Some/Module.pm'); my $mod = Module::Info->new_from_module('Some::Module'); my $mod = Module::Info->new_from_loaded('Some::Module'); my @mods = Module::Info->all_installed('Some::Module'); my $name = $mod->name; my $version = $mod->version; my $dir = $mod->inc_dir; my $file = $mod->file; my $is_core = $mod->is_core; # Only available in perl 5.6.1 and up. # These do compile the module. my @packages = $mod->packages_inside; my @used = $mod->modules_used; my @subs = $mod->subroutines; my @isa = $mod->superclasses; my @calls = $mod->subroutines_called; # Check for constructs which make perl hard to predict. my @methods = $mod->dynamic_method_calls; my @lines = $mod->eval_string; *UNIMPLEMENTED* my @lines = $mod->gotos; *UNIMPLEMENTED* my @controls = $mod->exit_via_loop_control; *UNIMPLEMENTED* my @unpredictables = $mod->has_unpredictables; *UNIMPLEMENTED* # set/get Module::Info options $self->die_on_compilation_error(1); my $die_on_error = $mod->die_on_compilation_error; $self->safe(1); my $safe = $mod->safe; DESCRIPTION
Module::Info gives you information about Perl modules without actually loading the module. It actually isn't specific to modules and should work on any perl code. METHODS
Constructors There are a few ways to specify which module you want information for. They all return Module::Info objects. new_from_file my $module = Module::Info->new_from_file('path/to/Some/Module.pm'); Given a file, it will interpret this as the module you want information about. You can also hand it a perl script. If the file doesn't exist or isn't readable it will return false. new_from_module my $module = Module::Info->new_from_module('Some::Module'); my $module = Module::Info->new_from_module('Some::Module', @INC); Given a module name, @INC will be searched and the first module found used. This is the same module that would be loaded if you just say "use Some::Module". If you give your own @INC, that will be used to search instead. new_from_loaded my $module = Module::Info->new_from_loaded('Some::Module'); Gets information about the currently loaded version of Some::Module. If it isn't loaded, returns false. all_installed my @modules = Module::Info->all_installed('Some::Module'); my @modules = Module::Info->all_installed('Some::Module', @INC); Like new_from_module(), except all modules in @INC will be returned, in the order they are found. Thus $modules[0] is the one that would be loaded by "use Some::Module". Information without loading The following methods get their information without actually compiling the module. name my $name = $module->name; $module->name($name); Name of the module (ie. Some::Module). Module loaded using new_from_file() won't have this information in which case you can set it yourself. version my $version = $module->version; Divines the value of $VERSION. This uses the same method as ExtUtils::MakeMaker and all caveats therein apply. inc_dir my $dir = $module->inc_dir; Include directory in which this module was found. Module::Info objects created with new_from_file() won't have this info. file my $file = $module->file; The absolute path to this module. is_core my $is_core = $module->is_core; Checks if this module is the one distributed with Perl. NOTE This goes by what directory it's in. It's possible that the module has been altered or upgraded from CPAN since the original Perl installation. Information that requires loading. WARNING! From here down reliability drops rapidly! The following methods get their information by compiling the module and examining the opcode tree. The module will be compiled in a seperate process so as not to disturb the current program. They will only work on 5.6.1 and up and requires the B::Utils module. packages_inside my @packages = $module->packages_inside; Looks for any explicit "package" declarations inside the module and returns a list. Useful for finding hidden classes and functionality (like Tie::StdHandle inside Tie::Handle). KNOWN BUG Currently doesn't spot package changes inside subroutines. package_versions my %versions = $module->package_versions; Returns a hash whose keys are the packages contained in the module (these are the same as what's returned by "packages_inside()"), and whose values are the versions of those packages. modules_used my @used = $module->modules_used; Returns a list of all modules and files which may be "use"'d or "require"'d by this module. NOTE These modules may be conditionally loaded, can't tell. Also can't find modules which might be used inside an "eval". modules_required my %required = $module->modules_required; Returns a list of all modules and files which may be "use"'d or "require"'d by this module, together with the minimum required version. The hash is keyed on the module/file name, the corrisponding value is an array reference containing the requied versions, or an empty array if no specific version was required. NOTE These modules may be conditionally loaded, can't tell. Also can't find modules which might be used inside an "eval". subroutines my %subs = $module->subroutines; Returns a hash of all subroutines defined inside this module and some info about it. The key is the *full* name of the subroutine (ie. $subs{'Some::Module::foo'} rather than just $subs{'foo'}), value is a hash ref with information about the subroutine like so: start => line number of the first statement in the subroutine end => line number of the last statement in the subroutine Note that the line numbers may not be entirely accurate and will change as perl's backend compiler improves. They typically correspond to the first and last run-time statements in a subroutine. For example: sub foo { package Wibble; $foo = "bar"; return $foo; } Taking "sub foo {" as line 1, Module::Info will report line 3 as the start and line 4 as the end. "package Wibble;" is a compile-time statement. Again, this will change as perl changes. Note this only catches simple "sub foo {...}" subroutine declarations. Anonymous, autoloaded or eval'd subroutines are not listed. superclasses my @isa = $module->superclasses; Returns the value of @ISA for this $module. Requires that $module->name be set to work. NOTE superclasses() is currently cheating. See CAVEATS below. subroutines_called my @calls = $module->subroutines_called; Finds all the methods and functions which are called inside the $module. Returns a list of hashes. Each hash represents a single function or method call and has the keys: line line number where this call originated class class called on if its a class method type function, symbolic function, object method, class method, dynamic object method or dynamic class method. (NOTE This format will probably change) name name of the function/method called if not dynamic Information about Unpredictable Constructs Unpredictable constructs are things that make a Perl program hard to predict what its going to do without actually running it. There's nothing wrong with these constructs, but its nice to know where they are when maintaining a piece of code. dynamic_method_calls my @methods = $module->dynamic_method_calls; Returns a list of dynamic method calls (ie. "$obj-"$method()>) used by the $module. @methods has the same format as the return value of subroutines_called(). Options The following methods get/set specific option values for the Module::Info object. die_on_compilation_error $module->die_on_compilation_error(0); # default $module->die_on_compilation_error(1); my $flag = $module->die_on_compilation_error; Sets/gets the "die on compilation error" flag. When the flag is off (default), and a module fails to compile, Module::Info simply emits a watning and continues. When the flag is on and a module fails to compile, Module::Info "die()"s with the same error message it would use in the warning. safe $module->safe(0); # default $module->safe(1); # be safer my $flag = $module->safe; Sets/gets the "safe" flag. When the flag is enabled all operations requiring module compilation are forbidden and the "version()" method executes its code in a "Safe" compartment. use_version $module->use_version(0); # do not use version.pm (default) $module->use_version(1); # use version.pm, die if not present my $flag = $module->use_version; Sets/gets the "use_version" flag. When the flag is enabled the 'version' method always returns a version object. AUTHOR
Michael G Schwern <schwern@pobox.com> with code from ExtUtils::MM_Unix, Module::InstalledVersion and lots of cargo-culting from B::Deparse. Mattia Barbon <mbarbon@cpan.org> is the current maintainer. LICENSE
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. THANKS
Many thanks to Simon Cozens and Robin Houston for letting me chew their ears about B. CAVEATS
Code refs in @INC are currently ignored. If this bothers you submit a patch. superclasses() is cheating and just loading the module in a seperate process and looking at @ISA. I don't think its worth the trouble to go through and parse the opcode tree as it still requires loading the module and running all the BEGIN blocks. Patches welcome. I originally was going to call superclasses() isa() but then I remembered that would be bad. All the methods that require loading are really inefficient as they're not caching anything. I'll worry about efficiency later. perl v5.12.1 2007-05-28 Module::Info(3)
All times are GMT -4. The time now is 01:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy