Setting Verbosity Option of Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Setting Verbosity Option of Script
# 1  
Old 02-27-2012
Setting Verbosity Option of Script

I have a script and I want the verbosity option to work in the following way:

User can either set quiet (no verbosity), use default verbosity level (when doing -v), or set a level value (when doing -v=2 or --vrbLevel=2).

I am making some more progress on this and am thinking of this idea.
Code:
if ($opt_quiet == 1) then
  set opt_verbose = 0                   # No verbosity allowed
  set vrbLevel = 0                        # Set to verbosity level 0 (quiet)
else if () then
  set                                             # Set to user level
else
  set vrbLevel = Def_vrbLevel    # Set default verbosity level
endif

The problem I am having is when I try to set the user value.

Code:
set ierr = 0
set iarg = 0
set opt_verbose = 0
set opt_usage = 0

set Def_vrbLevel = 1

set arg_fullNamesLst = ""
set narg = $#argv
while ($iarg < $narg)

  MATH iarg = $iarg + 1

  set arg = $argv[$iarg]
  set opt = `echo $arg | awk 'BEGIN {FS="="} {print $1}' | tr '[:lower:]' '[:upper:]'`
  set par = `echo $arg | awk 'BEGIN {FS="="} {print $2}'`

  switch ($opt)

    case "-V":
    case "--VRB-LEVEL":
      set arg_vrbLevel = $par
      set opt_verbose = 1
      breaksw

    case "-Q":
    case "--QUIET":
      set opt_quiet = 0
      breaksw

    default:
      set arg_fullNamesLst = "$arg_fullNamesLst $arg"
      breaksw

  endsw

end   # while

if ($opt_quiet == 1) then
  set opt_verbose = 0
  set vrbLevel = 0
else if () then
  set vrbLevel = arg_vrbLevel
else
  set vrbLevel = $Def_vrbLevel
endif

if (($verbose == 1) && ($vrbLevel >=3)) then
  echo "Some information"
endif


Last edited by kristinu; 02-27-2012 at 01:12 PM..
# 2  
Old 02-27-2012
Quote:
Originally Posted by kristinu
The problem I am having is when I try to set the user value.
And what problem would that be?
# 3  
Old 02-27-2012
if the user passes -v=2 or -v=3 etc, things are fine, but if the user uses only -v I got to use the default.

My problem is how to check whether the user passed a number or not.

I need something like this I think.

Code:
if ($opt_quiet == 1) then
  set opt_verbose = 0
  set vrbLevel = 0
else if ($user_passed_number == 1) then
  set vrbLevel = $arg_vrbLevel
else
  set vrbLevel = Def_vrbLevel
endif

# 4  
Old 02-27-2012
That doesn't look like shell script. What shell is this?
# 5  
Old 02-27-2012
Quote:
That doesn't look like shell script. What shell is this?
kristinu is persisting with a "C Shell".
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Red Hat

Grub.conf kernel field boot messages verbosity configuration

I am trying to understand what are the differences of boot messages verbosity levels for the kernel field in grub.conf From my research, there appear to be three levels: quiet verbose debug I have also found documents that specify removing quiet from the kernel field. If this is done, is... (1 Reply)
Discussion started by: thaebich
1 Replies

2. Shell Programming and Scripting

Script to call a menu script and redirect each option to a text file

Hello, I want to design a script that will call an existing menu script and select options one by one and redirict the out put to a file. For example;- In the script MENU.sh there are 10 options i want to design a script MENU2.sh that will select option 2 3 4 6 7 10 and redirict the output... (4 Replies)
Discussion started by: spradha
4 Replies

3. Shell Programming and Scripting

Call one script option to other in shell script

HI Guys, My Script abc.sh 1) Checks 2) CA Scipt 3) CIA Script 0) Exit Enter Choice : Now if i select choice 2 then after finshed choice 2 wait for 40 min and run choice 3 what i can write in CA Scipt option: if then My Code : ... (3 Replies)
Discussion started by: pareshkp
3 Replies

4. Programming

Reading command line arguments and setting up values if option not provided

I have a C++ program. I read command line arguments, but if the value is not supplied, I default or make a calculation. Let's say I set it to a default value. I can code this in several ways. Here I show three ways. What would be the best way for maintaining this code? The program will get very... (2 Replies)
Discussion started by: kristinu
2 Replies

5. Shell Programming and Scripting

perl script command line option driven script

could someone show me a sample command line option driven script? i want to see an easy way to write one and how i can execute it using command line options such as typing in read.pl -i <id> -c <cmds> -s <start> -e <end> would read out all the commands run by ID . from start time to... (7 Replies)
Discussion started by: kpddong
7 Replies

6. Shell Programming and Scripting

recently introduced to the newer option for find...does an older option exist?

To find all the files in your home directory that have been edited in some way since the last tar file, use this command: find . -newer backup.tar.gz Is anyone familiar with an older solution? looking to identify files older then 15mins across several directories. thanks, manny (2 Replies)
Discussion started by: mr_manny
2 Replies

7. Shell Programming and Scripting

Need help with script option

Hi, So my script reads $1 on the command line. example: SCRIPT_NAME 1111 In my script I use a nawk statement to grab $1 but I also need it to read $1 from the variable (1111 from command line in the example) nawk -F, '($1~1111)' *.$date.* What can I do so that this nawk statement... (2 Replies)
Discussion started by: llsmr777
2 Replies

8. Shell Programming and Scripting

\n option in script

I have a series of around 20 files as my program output. The final line of my script gets the no of files and the file list for the present day. The no of files shoudl be printed first and the files for today must be printed in the next line. Ialso understood that echo -e must be used for with \n.... (4 Replies)
Discussion started by: venkidhadha
4 Replies

9. Shell Programming and Scripting

option followed by : taking next option if argument missing with getopts

Hi all, I am parsing command line options using getopts. The problem is that mandatory argument options following ":" is taking next option as argument if it is not followed by any argument. Below is the script: while getopts :hd:t:s:l:p:f: opt do case "$opt" in -h|-\?)... (2 Replies)
Discussion started by: gurukottur
2 Replies
Login or Register to Ask a Question