Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Accepting command line arguments in bash Post 302606998 by Scrutinizer on Tuesday 13th of March 2012 10:00:56 AM
Old 03-13-2012
Here is a start, run through a basic converter script. There will undoubtedly be things that will need to be edited manually.

Code:
arg_browseDir_inFileLst=""
allArgsUpCase=`echo "$*" | tr '[:lower:]' '[:upper:]'`
opt_browseDir_flag=`echo $allArgsUpCase | awk '/BRWS/ {print 1}; ! /BRWS/ {print 0}'`

narg=$#
while (($iarg < $narg))

  (( iarg = $iarg + 1 ))
  arg=$argv[$iarg]
  opt_usrInputFlag=`echo $arg | awk '/=/ {print 1}; ! /=/ {print 0}'`
  opt=`echo $arg | awk 'BEGIN {FS="="} {print $1}' | tr '[:lower:]' '[:upper:]'`
  par=`echo $arg | awk 'BEGIN {FS="="} {print $2}'`

  case $opt in

  # -- Mandatory Arguments -------------------------------------------------------------------------

  "--NXZ":                        # Mandatory)
  "--NX-NZ")
    arg_nxz=$par
    opt_nxz=1
    ;;

  "--VARP")
    arg_varp=$par
    opt_varp=1
    ;;

  # -- Optional Arguments --------------------------------------------------------------------------

  "--DRWPTH")
  "--TDARWIN-PATH")
    arg_drwPath=$par
    opt_drwPath=1
    ;;

  "--BASEIF")
  "--BASE-INFILE")
    arg_baseInFile=$par
    opt_baseInFile=1
    ;;

  "-DATAIF")
  "--DATA-INFILE")
    arg_tdatInFile=$par
    opt_tdatInFile=1
    ;;

  "--CMODIF")
  "--CMOD-INFILE")
    arg_cmodInFile=$par
    opt_cmodInFile=1
    ;;

  "--CMODOF")
  "--CMOD-OUTFILE")
    arg_cmodOutFile=$par
    opt_cmodOutFile=1
    ;;

  "--RSTRIF")
  "--RSTR-INFILE")
    arg_rstrInFile=$par
    opt_rstrInFile=1
    ;;

  "--NPOP")
    arg_npop=$par
    opt_npop=1
    ;;

  "--SG")
  "--SIGMA")
    arg_sigma=$par
    opt_sigma=1
    ;;

  "-DRW-V")
  "-DRW-VERBOSE")
  "-DRW-VRB-LEVEL")
  "--TDARWIN-VERBOSITY-LEVEL")
    arg_drwVrb=$par
    opt_drwVrb=1
    ;;

 "--BRWSDIR-CHECK":                       # Separates numbers from characters.)
  "--BRWSDIR-CHECK-COLPOS")
    opt_browseDir_chkColPos=1
    ;;

  "--BRWSDIR-SORT")
  "--BRWSDIR-SORT-FIELDS")
    arg_browseDir_sortPtn=$par
    opt_browseDir_sortFlds=1
    ;;

  "--BRWSDIR-GROUP")
  "--BRWSDIR-GROUP-TABLE")
    arg_browseDir_groupPtn=$par
    opt_browseDir_groupTbl=1
    ;;

  "--BRWSDIR-ALL")
  "--BRWSDIR-ALL-FILES")
    opt_browseDir_allFiles=1
    ;;

  "--BRWSDIR-RAYTRAC":                      # Display files related to raytrac.)
  "--BRWSDIR-RAYTRAC-FILES")
    opt_browseDir_raytracFiles=1
    ;;

  *)
    arg_browseDir_inFileLst="$arg_browseDir_inFileLst $arg"
    opt_browseDir_inFileLst=1
    ;;

  esac

end   # while

Converted with csh2sh.pl by Olivier Aubert

---------- Post updated at 15:00 ---------- Previous update was at 14:59 ----------

getopts cannot handle long options. Only the very latest ksh93 can do this...

Last edited by Scrutinizer; 03-13-2012 at 11:07 AM..
This User Gave Thanks to Scrutinizer For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash: Reading 2 arguments from a command line

If no arguments are entered I wanna be able to read 2 arguments, i have done like this but it doesnt work: x=0 until #loop starts do if ; then echo No arguments were entered, please enter 2 arguments. read $1 $2 elif || ; then echo $#... (0 Replies)
Discussion started by: Vozx
0 Replies

2. UNIX for Dummies Questions & Answers

arguments in command line

Hi all, How many arguments can we pass while testing a prgm at command line.. I encountered an issue while passing 10 arguments. For $10 its taking argument passed for $1 followed by 'zero'. can we pass more than 9 arguments /Is there any other way. Thanks, rrs (6 Replies)
Discussion started by: rrs
6 Replies

3. Shell Programming and Scripting

Accepting filename as command line param and writing to it

Hi, Is it possible to accept a filename as command line parameter and then write to that file using command redirection? i tried the below script. outputfile=`echo $1` echo "Writing to file" > 'echo $outputfile' exit $returncode but it isnt working. is there any other way to... (9 Replies)
Discussion started by: silas.john
9 Replies

4. UNIX for Dummies Questions & Answers

Command line arguments.

I am working on a script wherein i need the user to enter the Build ID for eg:the command line will show enter the build ID Now on entering the build ID it should be assigned to @ARGV. How can this be done.? (1 Reply)
Discussion started by: Varghese
1 Replies

5. Shell Programming and Scripting

Help parsing command line arguments in bash

Looking for a little help parsing some command line arguments in a bash script I am working on, this is probably fairly basic to most, but I do not have much experience with it. At the command line, when the script is run, I need to make sure the argument passed is a file, it exists in the... (3 Replies)
Discussion started by: Breakology
3 Replies

6. UNIX for Dummies Questions & Answers

command line arguments

hi, can someone how to accept command line arguments as a variable using in script? like: ./scriptname arguments by accept arguments, I can use it in my script? thx! (1 Reply)
Discussion started by: ikeQ
1 Replies

7. Shell Programming and Scripting

Accepting user input and arguments in PERL

Hi All, Can we pass arguments while calling the perl script and as well as ask user input during execution of the script? My program is as below: I am passing arg1 and arg2 as argements to test.pl ]./test.pl arg1 arg2 Inside the test.pl I have : print "Do you want a name ? (y/n) : ";... (2 Replies)
Discussion started by: jisha
2 Replies

8. Shell Programming and Scripting

command line arguments

hi,,,, I want to create a command prompt, for example "prompt>", so my prompt need to handle commands, for example "prompt>cmd", so i want to know how to get arguments for my own commands cmd, i.e. default argc should contain arguments count and argv should point to the argument vector i.e, for... (2 Replies)
Discussion started by: vins_89
2 Replies

9. Shell Programming and Scripting

Passing arguments from a bash shell script to a command

I'm pretty new to bash scripting and I've found myself writing things like this (and the same with even more nesting): if $CATEGORIES; then if $LABEL_SLOTS; then $pyth "$wd/texify_grammar.py" "$input" "$texfile" "--label-slots" "--categories" "$CATEGORY_LIST" ... (9 Replies)
Discussion started by: burbly
9 Replies

10. Shell Programming and Scripting

Wanted: Help with escaping bash command line arguments

Please forgive me if this is the wrong forum. I want to execute some one liners with the groovy programming language and I'm having trouble escaping the special characters to accommodate bash. Here is one of the lines that is giving me trouble: groovy -e "(new... (1 Reply)
Discussion started by: siegfried
1 Replies
All times are GMT -4. The time now is 09:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy