Sponsored Content
Full Discussion: Passing arguments
Top Forums UNIX for Dummies Questions & Answers Passing arguments Post 302454497 by PowerPaul on Saturday 18th of September 2010 02:36:23 PM
Old 09-18-2010
Here you go:
Code:
#!/bin/bash
# short arguments
while getopts  ":a:b:" OPTION
    do
        case $OPTION in
            a)
                PARAM1=$OPTARG
                echo short PARAM1 set to $PARAM1
                ;;
            b)
                PARAM2=$OPTARG
                echo short PARAM2 set to $PARAM2
                ;;
            *)
                break;;
         esac
    done

# long arguments
while [ $# -gt 0 ]
do
    case "$1" in
       -parameter1)
                    PARAM1=$2;
                    echo long PARAM1 set to $PARAM1
                    shift;;
       -parameter2) 
                    PARAM2=$2;
                    echo long PARAM2 set to $PARAM2
                    shift;;
       *)         
                    shift;;
    esac
    shift
done


Code:
./myscript.sh -a "AA;BB;CC" -b "DD;E" -parameter1 "AA;BB;CC" -parameter2 "DD;E"
short PARAM1 set to AA;BB;CC
short PARAM2 set to DD;E
long PARAM1 set to AA;BB;CC
long PARAM2 set to DD;E

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

passing arguments

I'm trying to pass a filename, or all the files in the current directory to the ls command with a script. Unsuccessful so far, here are a few of my attempts: #!/bin/ksh read fname #if (( $# > 0 )); then $fname | ls -l #fi this produces a long listing of all the files in my current... (4 Replies)
Discussion started by: jpprial
4 Replies

2. Shell Programming and Scripting

Passing and using arguments in Scripts.

I am new to scripting in AIX / UNIX. I have a script that runs 4 other scripts and I want to be able to pass in a agrument that I can check before I run the next script to see if the previous script finished with no errors. Can someone send me an example of this as I'm sure it's pretty easy to... (1 Reply)
Discussion started by: David.Vilmain
1 Replies

3. Shell Programming and Scripting

Passing Arguments-Help

Hi, I have a script which adds the user credentials to an ldap server. Im passing the variables as below.. /path/my_script $uname $pwd $environ ${deposit} If i enter some special characters like ';' in $pwd, script returns an error which is set to display if the user enters... (5 Replies)
Discussion started by: Tuxidow
5 Replies

4. Shell Programming and Scripting

passing arguments

Hi I have a script to which I pass multiple arguments, for example lets say the script name is "abc". I run the script like ./abc def /file <directory location> In the above "def" is the first argument and "/file" is the second argument. I expect <directory location> that is passed after... (4 Replies)
Discussion started by: zmfcat1
4 Replies

5. Shell Programming and Scripting

Passing arguments to awk

I have an awk script below which I call using for example awk -f ../../A-Scripts/select-model.awk iterations.txt 16x12 10 I want to be able to use it in a different way like this awk -f ../../A-Scripts/select-model.awk iterations.txt nxz=16x12 iter=10 or awk -f... (1 Reply)
Discussion started by: kristinu
1 Replies

6. Shell Programming and Scripting

Passing arguments to csh

I have noticed this thing using csh when passing arguments Suppose I call a csh script using ../Scripts/plot-model.csh -vmod="npt02-z30.vmod" -R="0/80/0/30" -c="0/4.5" -aspr="1:10" Somehow the " get removed when doing $argv ending up with -vmod=npt02-z30.vmod... (0 Replies)
Discussion started by: kristinu
0 Replies

7. Shell Programming and Scripting

Passing arguments to python

How can I pass arguments to a python script??? (3 Replies)
Discussion started by: kristinu
3 Replies

8. Shell Programming and Scripting

Reading a string and passing passing arguments to a while loop

I have an for loop that reads the following file cat param.cfg val1:env1:opt1 val2:env2:opt2 val3:env3:opt3 val4:env4:opt4 . . The for loop extracts the each line of the file so that at any one point, the value of i is val1:env1:opt1 etc... I would like to extract each... (19 Replies)
Discussion started by: goddevil
19 Replies

9. Shell Programming and Scripting

Passing arguments--Error

Hi, i have a file.txt with data Bangalore Chennai Hyd filename of the script is: new.sh result=`cat file.txt | grep $1` if then echo pass else echo fail fi i am executing the file in the cmd line as "sh new.sh Bangalore" o/p is pass if i give "sh new.sh delhi" o/p is... (6 Replies)
Discussion started by: harsha85
6 Replies

10. Shell Programming and Scripting

Using here document when passing arguments

I have a script test.sh which reads various inputs from a user. #!/bin/ksh read x read y read z echo x: $x y: $y z: $z # read few more things again read a read b echo a: $a b: $b When i run this script as test.sh << EOF 1 2 EOF (3 Replies)
Discussion started by: ariesb2b
3 Replies
Tie::iCal(3pm)						User Contributed Perl Documentation					    Tie::iCal(3pm)

NAME
Tie::iCal - Tie iCal files to Perl hashes. VERSION
This document describes version 0.14 released 1st September 2006. SYNOPSIS
use Tie::iCal; tie %my_events, 'Tie::iCal', "mycalendar.ics" or die "Failed to tie file! "; tie %your_events, 'Tie::iCal', "yourcalendar.ics" or die "Failed to tie file! "; $my_events{"A-NEW-UNIQUE-ID"} = [ 'VEVENT', { 'SUMMARY' => 'Bastille Day Party', 'DTSTAMP' => '19970714T170000Z', 'DTEND' => '19970715T035959Z', } ]; tie %our_events, 'Tie::iCal', "ourcalendar.ics" or die "Failed to tie file! "; # assuming %my_events and %your_events # have no common keys (unless that's your intention) # while (my($uid,$event) = each(%my_events)) { $our_events{$uid} = $event; } while (my($uid,$event) = each(%your_events)) { $our_events{$uid} = $event; } untie %our_events; untie %your_events; untie %my_events; DEPENDENCIES
Tie::File DESCRIPTION
Tie::iCal represents an RFC2445 iCalendar file as a Perl hash. Each key in the hash represents an iCalendar component like VEVENT, VTODO or VJOURNAL. Each component in the file must have a unique UID property as specified in the RFC 2445. A file containing non-unique UIDs can be converted to have only unique UIDs (see samples/uniquify.pl). The module makes very little effort in understanding what each iCalendar property means and concentrates on the format of the iCalendar file only. FILE LOCKING
The Tie::iCal object returned by tie can also be used to access the underlying Tie::File object. This is accessible via the 'A' class variable. This may be useful for file locking. my $ical = tie %events, 'Tie::iCal', "mycalendar.ics"; $ical->{A}->flock; DATES
The iCalendar specification uses a special format for dates. This module makes no effort in trying to interpret dates in this format. You should look at the Date::ICal module that can convert between Unix epoch dates and iCalendar date strings. How Tie::iCal interprets iCal files Tie::iCal interprets files by mapping iCal components into Perl hash keys and iCal content lines into various Perl arrays and hashes. Components An iCal component such as VEVENT, VTODO or VJOURNAL maps to a hash key:- BEGIN:VEVENT UID:a_unique_uid NAME1:VALUE1 .. END:VEVENT corresponds to $events{'a_unique_uid'} = ['VEVENT', {'NAME1' => 'VALUE1'}] Subcomponents An iCal subcomponent such as VALARM maps to a list of hash keys:- BEGIN:VALARM TRIGGER;VALUE=DURATION:-PT1S TRIGGER;VALUE=DURATION:-PT1S END:VALARM BEGIN:VALARM X-TIE-ICAL;VALUE=ANOTHER:HERE X-TIE-ICAL:HERE2 X-TIE-ICAL-NAME:HERE2 END:VALARM corresponds to 'VALARM' => [ { 'TRIGGER' => [ [{'VALUE' => 'DURATION'},'-PT1S'], [{'VALUE' => 'DURATION'},'-PT1S'] ] }, { 'X-TIE-ICAL' => [ [{'VALUE' => 'ANOTHER'},'HERE'], ['HERE2'] ], 'X-TIE-ICAL-NAME' => 'HERE2' } ] To see how individual content lines are formed see below. Content Lines Once unfolded, a content line may look like:- NAME;PARAM1=PVAL1;PARAM2=PVAL2;...:VALUE1,VALUE2,... having an equivalent perl data structure like: - 'NAME' => [{'PARAM1'=>'PVAL1', 'PARAM2'=>'PVAL2', ..}, 'VALUE1', 'VALUE2', ..] or NAME:VALUE1,VALUE2,... having an equivalent perl data structure like: - 'NAME' => ['VALUE1', 'VALUE2', ..] or NAME:VALUE having an equivalent perl data structure like: - 'NAME' => 'VALUE' An blank value is mapped from NAME: to 'NAME' => '' Multiple contentlines with same name, i.e. FREEBUSY, ATTENDEE:- NAME;PARAM10=PVAL10;PARAM20=PVAL20;...:VALUE10,VALUE20,... NAME;PARAM11=PVAL11;PARAM21=PVAL21;...:VALUE11,VALUE21,... ... having an equivalent perl data structure like: - 'NAME' => [ [{'PARAM10'=>'PVAL10', 'PARAM20'=>'PVAL20', ..}, 'VALUE10', 'VALUE20', ..], [{'PARAM11'=>'PVAL11', 'PARAM21'=>'PVAL21', ..}, 'VALUE11', 'VALUE21', ..], ... ] or NAME:VALUE10,VALUE20,... NAME:VALUE11,VALUE21,... ... having an equivalent perl data structure like: - 'NAME' => [ ['VALUE10', 'VALUE20', ..], ['VALUE11', 'VALUE21', ..], ... ] or in a mixed form, i.e. NAME:VALUE10,VALUE20,... NAME;PARAM11=PVAL11;PARAM21=PVAL21:VALUE11,VALUE21,... NAME:VALUE12,VALUE22,... ... having an equivalent perl data structure like: - 'NAME' => [ ['VALUE10', 'VALUE20', ..], [{'PARAM11'=>'PVAL11', 'PARAM21'=>'PVAL21', ..}, 'VALUE11', 'VALUE21', ..], ['VALUE12', 'VALUE22', ..], ... ] BUGS
Property names are assumed not to be folded, i.e. DESCR IPTION:blah blah.. RRULE property does not support parameters. Property names that begin with UID can potentially confuse this module. Subcomponents such as VALARM must exist after any UID property. Deleting events individually may leave non-RFC2445 compliant empty VCALENDAR objects. AUTHOR
Blair Sutton, <mailto:bsdz@cpan.org>, <http://www.numeninest.com/> COPYRIGHT
Copyright (c) 2006 Blair Sutton. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
perl, Tie::File, Date::ICal perl v5.12.4 2011-11-11 Tie::iCal(3pm)
All times are GMT -4. The time now is 01:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy