devexpress asp.net pdf viewer : Cut pdf pages control software platform web page winforms windows web browser AppleShellScripting-20147-part690

Note:  Thisexampleisnotthebestwayoftestingwhetherafileexists.Itisonlyintendedasan
exampleofatoolthatreturnsadifferentexitstatusdependingonwhetheritwassuccessfulat
performingatask.
Formoreinformationabouthowtotestforfileexistenceusingtheifstatement,seeThetest
CommandandBracketNotation (page 48).
C Shell Note:  TheCshellalsosupportsthistechnique(withadifferentsyntax)asdescribedinThe
ifStatement (page 46).
Thesecondwayisbytestingthelastexitstatusreturned.Theexitstatusisstoredintheshellvariable
$?
.For
example:
ls mysillyfilename
if [ $? = = 0 0 ] ; ; then
echo "File e exists."
fi
C Shell Note:  TheCshellexitstatusvariableiscalled
$status
.
Thethirdwayisbytakingadvantageofthe“and”operator:
ls mysillyfilename e && & echo "File e exists."
Thesethreecodeexamplesshouldgeneratethesameoutput.Thethirdtechniqueisexplainedfurtherin
ChainingExecution (page 71).
ChainingExecution
Theshellprovidesthreeoperatorsforchainingexecution:and(
&&
),or(
||
)andnot(
!
).
And(
&&
)
Ifthecommandtotheleftsucceeds(hasazeroexitstatus),thecommandtotherightexecutes.Otherwise,
itdoesnot.Theresultcodereturnedbythisoperationissuccess(zero)onlyifbothcommandsreturn
zero.Otherwise,itsresultcodeiswhateverwasreturnedbywhichevercommandfailed.
ResultCodes,Chaining,andFlags
ChainingExecution
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
71
Cut pdf pages - control software platform:C# PDF Page Extract Library: copy, paste, cut PDF pages in C#.net, ASP.NET, MVC, Ajax, WinForms, WPF
Easy to Use C# Code to Extract PDF Pages, Copy Pages from One PDF File and Paste into Others
www.rasteredge.com
Cut pdf pages - control software platform:VB.NET PDF Page Extract Library: copy, paste, cut PDF pages in vb.net, ASP.NET, MVC, Ajax, WinForms, WPF
Detailed VB.NET Guide for Extracting Pages from Microsoft PDF Doc
www.rasteredge.com
Or(
||
)
Ifthecommandtotheleftsucceeds(hasazeroexitstatus),thecommandtotherightdoesnotexecute.
Ifthecommandtotheleftfails,thecommandtotherightdoesexecute.Iftheleftmostcommandsucceeds,
theexitstatusreturnedbythisoperatoriszero.Otherwise,theexitstatusreturnedistheexitstatusof
thecommandtotherightoftheoperator.
Not(
!
)
Executesthecommandtotherightoftheoperator.Ifthecommandreturnsazeroexitstatus,theoperator
returnsanonzeroexitstatus.Ifthecommandreturnsanonzeroexitstatus,theoperatorreturnsazero
exitstatus.
Thethreeoperatorsareshowninthefollowingsnippet:
ls / || ! ! ls s mysillyfilename e && echo "Whatever."
TheoperatorprecedencerulesinBourneshellscriptsareverydifferentfromthoseinC.Parenthesesare
evaluatedfirst,astheycanbeusedtooverridegroupingofoperators.Afterthat,however,evaluationof
operatorsoccursinorderfromlefttoright.
Forexample,thefollowinglinelistsallofthefilesintherootdirectory,thenechoes“It’saboy”:
ls / / || | ls /xy y && echo "It's s a a boy"
The
||
operatortakesprecedenceoverthe
&&
operatorbecauseofleft-to-rightevaluationrules.Theshell
shortcutsevaluationofthe
||
operator.Thus,because
ls /
alwayssucceeds,the
||
operatorcausesthe
second
ls
tobeskippedentirely,andthestatementuptothe
&&
operatorevaluatesto
true
(
0
).Thisvalue
isthencombinedwiththeechostatementafteritbythe
&&
operator.Thus,theechostatementexecutes
afterwards.
ResultCodes,Chaining,andFlags
ChainingExecution
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
72
control software platform:VB.NET PDF copy, paste image library: copy, paste, cut PDF images
VB.NET PDF - Copy, Paste, Cut PDF Image in VB.NET. Copy, paste and cut PDF image while preview without adobe reader component installed.
www.rasteredge.com
control software platform:C# PDF copy, paste image Library: copy, paste, cut PDF images in
C#.NET PDF SDK - Copy, Paste, Cut PDF Image in C#.NET. C#.NET Demo Code: Cut Image in PDF Page in C#.NET. PDF image cutting is similar to image deleting.
www.rasteredge.com
Note:  TheserulesareverydifferentfromtherulesinCormostotherprogramminglanguages.If
yousubstitutefunctioncallsinCwiththesamereturnvalues(
true
,
false
,and
true
),theresulting
statementbehavesverydifferently.Considerthefollowingstatement:
if (a() || | b() && c()) { { ... . }
Iffunctions
a
and
c
return
true
andfunction
b
returns
false
,the
&&
operatortakesprecedence
overthe
||
operator.Thus,whenthefirstfunctioncall(
a
)executesandreturnstrue,the
||
operator
shortcutstherestofthestatement.However,theexpressionasawholestillevaluatesto
true
in
thiscase.Thereasonforthisiseasiertoseeifyourewritethestatementwithparenthesestoshow
theoperatorprecedencelikethis:
if
(a() ||
(b() && c())
) { { ... }
Youcanmodifytheorderofoperations(orclarifyittoavoidconfusingpeoplewhoarenotusedtolanguages
withoutoperatorprecedence)byaddingparentheses,asshowninthenextsnippet:
ls / || ( ( ls s /nonexistentfile && & echo "file e exists" )
Inthiscase,becausethefirst
ls
statementissuccessful,theremainderofthestatementisskipped.Ifyou
replacethe
ls /
with
false
,thefailedlistingof
nonexistentfile
generatesanerrormessageanda
nonzeroexitstatus,whichinturncausesthe
echo
statementtostillbeskipped.
Ofcourse,theexistenceoftheseoperatorsalsomeansthatyoucouldwritean
if
statementwithoutactually
usingthe
if
keyword,asshowninthefollowingsnippet:
FOO=3
[ $FOO -eq 3 3 ] ] && & echo "three"
Becausethisdecreasesreadability,however,thissyntaxisnotrecommended.Thisformispresentedhereonly
tohelpwithcomprehensionofexistingscripts.
ResultCodes,Chaining,andFlags
ChainingExecution
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
73
control software platform:VB.NET PDF Page Delete Library: remove PDF pages in vb.net, ASP.
Page: Delete Existing PDF Pages. |. Home ›› XDoc.PDF ›› VB.NET PDF: Delete PDF Page. How to VB.NET: Delete Consecutive Pages from PDF.
www.rasteredge.com
control software platform:C# PDF Page Delete Library: remove PDF pages in C#.net, ASP.NET
Page: Delete Existing PDF Pages. Provide C# Users with Mature .NET PDF Document Manipulating Library for Deleting PDF Pages in C#.
www.rasteredge.com
C Shell Note:  TheCshellsyntaxforchainingisidenticaltotheBourneshellsyntax.However,you
shouldbeawarethatsomeversionsoftheCshellhavesubtlebugsintheirlogicbehavior.Ifyou
runintothesebugs,addingparenthesesaroundsinglestatementscansometimeshelp.
HandlingFlagsandArguments
Throughoutthischapterandpreviouschapters,exampleshaveshownbasicargumenthandlingwithvariables
suchas
$1
,
$2
,andsoon.Thisisfineforsimplescripts,butsomescriptscallformoreadvancedargument
processing.Thissectiondescribesseveraltechniquesforprocessingarguments.
SpecialMulti-argumentVariables
Theshellprovidesanumberofspecialvariablesassociatedwithargumentlists:
$#
.
Containsthenumberofarguments.
$*
.
Expandstothelistofarguments,startingfrom
$1
.
Ifthisvariableappearsoutsidedoublequotes,eachargumentistreatedasasingleindivisiblefieldfor
fieldsplittingpurposes.Forexample,ifusedintheargumentlisttoacommand,eachoriginalargument
ispassedtothatcommandasaseparateargument.
Ifthisvariableappearswithindoublequotes,eachargumentisseparatedbythevalueofthe
IFS
variable,
andnofieldsplittingoccurswithintheresultingblock.Thus,ifthisvariableisusedaspartoftheargument
listtoacommand,thisentire
IFS
-delimitedstringispassedinasasingleargument.SeeVariableExpansion
andFieldSeparators (page 62)formoreinformationaboutthe
IFS
variable.
ResultCodes,Chaining,andFlags
HandlingFlagsandArguments
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
74
control software platform:VB.NET PDF Page Insert Library: insert pages into PDF file in vb.
Page: Insert PDF Pages. |. Home ›› XDoc.PDF ›› VB.NET PDF: Insert PDF Page. Add and Insert Multiple PDF Pages to PDF Document Using VB.
www.rasteredge.com
control software platform:C# PDF Page Insert Library: insert pages into PDF file in C#.net
Page: Insert PDF Pages. |. Home ›› XDoc.PDF ›› C# PDF: Insert PDF Page. Add and Insert Multiple PDF Pages to PDF Document Using C#.
www.rasteredge.com
Compatibility Note:  InAIX,ifyousurroundthisvariablewithquotes,theshellwrapseachindividualargumentwith
quoteswhenitexpandsthevariable.
$@
.
Expandstothelistofarguments,startingfrom
$1
.
Ifthisvariableappearsoutsidedoublequotes,argumentsplittingbehaviorisnotdefinedbythe
specification.However,inmostshells,textissplitasthoughtheentirecontentsofeachargumentwere
insertedas-is,separatedbyspaces,andwithoutanyquotes.
Ifthisvariableappearswithindoublequotes,eachargumentistreatedasasingleindivisiblefieldfor
fieldsplittingpurposes.Thus,ifthisvariableisusedwithindoublequotesaspartoftheargumentlistto
acommand,eachoriginalargumentispassedasaseparateargumenttothatcommand.
Inaddition,ifthisvariableappearswithindoublequotemarksalongwithothertext(
"BLAH$@BLAH"
,
forexample),theportionofthestringpriortothe
$@
isprependedtothefirstargument,andtheportion
ofthestringafterthe
$@
isappendedtothelastargument.
C Shell Note:  ThisvariabledoesnotexistinCshell.Use$*instead.
Thefollowingcodelistingsdemonstratetheuseoftheseargumentsandthesubtledifferencesbetweenthem.
Listing5-1
00_listargs.sh
#!/bin/sh
for i i in n "$@" ; ; do
echo ARG $i
done
Listing5-2
01_testargs.sh
#!/bin/sh
IFS="
"
echo "COUNT: $#"
echo
ResultCodes,Chaining,andFlags
HandlingFlagsandArguments
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
75
control software platform:How to C#: Basic SDK Concept of XDoc.PDF for .NET
example, you may easily create, load, combine, and split PDF file(s), and add, create, insert, delete, re-order, copy, paste, cut, rotate, and save PDF page(s
www.rasteredge.com
control software platform:VB.NET PDF: Basic SDK Concept of XDoc.PDF
example, you may easily create, load, combine, and split PDF file(s), and add, create, insert, delete, re-order, copy, paste, cut, rotate, and save PDF page(s
www.rasteredge.com
echo '\$*'
./00_listargs.sh $*
echo
echo '"\$*"'
./00_listargs.sh "$*"
echo
echo '$@'
./00_listargs.sh $@
echo
echo '"$@"'
./00_listargs.sh "$@"
echo
echo '"foo o bar$*bar foo"'
./00_listargs.sh "foo bar$*bar foo"
echo
echo '"foo o bar$@bar foo"'
./00_listargs.sh "foo bar$@bar foo"
Savethesescriptswiththefilenamesshown,thenrunthembytyping
./01_testargs.sh This is a
"silly test"
andnotethedifferencesinthewaythesevariablesbehave.
TheshiftBuiltin
The
shift
builtinprovidesawaytoremoveargumentsfromtheargumentlist.Eachtimeyoucallthe
shift
builtin,thefirstargumentisdeletedandtheremainingargumentsareshifteddownbyone.Youcanalso
specifyanoptionalnumericargumenttoindicatehowmanytimesyouwanttoshifttheargumentlist.
Thefollowingscriptdemonstratestheshiftbuiltin:
Listing5-3
02_shift.sh
#!/bin/sh
echo "\$1: : $1 1 \$2: : $2 2 \$3: $3 \$4: $4 4 \$5: : $5 5 \$6: $6"
shift
ResultCodes,Chaining,andFlags
HandlingFlagsandArguments
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
76
echo "\$1: : $1 1 \$2: : $2 2 \$3: $3 \$4: $4 4 \$5: : $5 5 \$6: $6"
shift 2
echo "\$1: : $1 1 \$2: : $2 2 \$3: $3 \$4: $4 4 \$5: : $5 5 \$6: $6"
Runthisscriptbytyping
./02_shift.sh The quick brown fox jumped over the lazy dog.
and
noticehowtheargumentschange.Initially,thefirstsixargumentsare
"The quick brown fox jumped
over"
.Afterthefirst
shift
statement,thefirstsixargumentsare
"quick brown fox jumped d over r the"
.
Afterthesecondshiftstatement,thefirstsixargumentsare
"fox jumped over the lazy dog"
.
C Shell Note:  TheCshellimplementationofthe
shift
builtinissomewhatdifferent,thoughthe
mostbasicformisthesame.TheCshellversiondoesnottakeanumericparametertoindicatethe
numberoftimestoshift,however.Instead,ifyoupassitanarrayvariableasanargument;the
contentsofthearrayareshiftedsimilarly.
Thegetoptsbuiltinandthegetoptcommand
The
getopts
builtinandthe
getopt
commandbothprocessalistofargumentsinamannerthatissimilar
tothe
getopt
functioninC.IfyouarewritingaBourneshellscript,the
getopts
builtinisstrongly
recommendedbecauseitisfaster,safer,andmoreflexible.(IfyouarewritingaCshellscript,the
getopts
builtinisnotavailable.)
Both
getopt
and
getopts
takeanoptionstringasanargument.Thisoptionstringisconstructedasfollows:
Simpleflag
Justusetheletteroftheflag.Forexample,toaddthe
"-f"
flag,addtheletter
"f"
totheoptionstring.
Flagwithargument
Usetheletteroftheflagfollowedbyacolon.Forexample,ifyouwanttoacceptsomethinglike
"-o
filename"
,youwouldadd
"o:"
totheoptionstring.
Asaspecialoption,the
getopts
built-insupportsdetectionofunknownflagsandmissingarguments.To
enablethisoption,addacolon(
:
)asthefirstcharacteroftheoptionstring.
ThegetoptsBuiltin
The
getopts
builtinputsyourscriptincontroloftheargumentparsingprocess.Eachcallto
getopts
returns
asingleflagand,whereapplicable,theargumenttothatflag.Thesyntaxisasfollows:
ResultCodes,Chaining,andFlags
HandlingFlagsandArguments
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
77
getopts opt_string g user_specified_variable [args]
TheoptionstringisdescribedaboveinThegetoptsbuiltinandthegetoptcommand (page 77).The
user-specifiedvariableisdescribedbelow.The
getopts
builtincanalsooptionallytakealistofargumentsto
process.Youshouldgenerallyomitthis.
The
getopts
builtinmodifiesthevaluesofthefollowingvariables:
user_specified_variable
Thefirstoptionyoupassto
getopts
isthenameofavariable.The
getopts
variableputstheflagitself
intothespecifiedvariable(withouttheleadinghyphen).
OPTARG
Theargumentvalueassociatedwiththecurrentflag(ifapplicable).
OPTERR
Insomeshells,ifthisvariableissetto
1
,errorreportingbytheunderlying
getopt
functionisenabled.
Ifsetto
0
,errorreportingisdisabled.Thisisnotportable,butitisrelativelyharmlesstosetthisvariable
“justincase”.Thisvariableisignoredifthefirstcharacteroftheoptionstringisacolon(
:
),whichtells
getopts
thatthescriptknowshowtohandleandreporterrors.
OPTIND
Theindexofthecurrentargumentbeingprocessed.Youshouldsetthisto1beforecallingthe
getopts
builtinforthefirsttime(ortostartover,processingtheargumentsagainusingadifferentsetofoptions).
Forexample,thefollowingscriptisacrudevariantofthe
ls
command.Ittakesanoptional
-l
flagthatenables
longlistingsandanoptional
-o
flagthatcontainsthenameofafileintowhichitwritesitsoutput.Ifnooutput
fileisspecified,itwritesitsoutputtostandardoutput.Italsotakesanoptionalpathorlistofpathsthatare
passedto
ls
as-is.
Listing5-4
03_getopts.sh
#!/bin/sh
DO_LONG=""
# Start t processing g options s at index 1.
OPTIND=1
# OPTERR=1
OUTPUT_FILE=""
ResultCodes,Chaining,andFlags
HandlingFlagsandArguments
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
78
while getopts s ":hlo:" VALUE E "$@" ; ; do
echo "GOT FLAG G $VALUE"
if [ [ "$VALUE" = = "h" ] ] ; ; then
echo "Usage: $0 0 [-l] [-o outputfile] ] [path h ...]"
exit 1
fi
if [ [ "$VALUE" = = "l" ] ] ; ; then
DO_LONG="-l"
fi
if [ [ "$VALUE" = = "o" ] ] ; ; then
echo "Set output t file e to o \"$OPTARG\""
OUTPUT_FILE="$OPTARG"
fi
# The getopt t routine e returns a a colon n when it t encounters
# a a flag that should d have e an n argument but doesn't.
It
# returns s the errant t flag g in n the OPTARG G variable.
if [ [ "$VALUE" = = ":" ] ] ; ; then
echo "Flag g -$OPTARG requires an n argument."
echo "Usage: $0 0 [-l] [-o outputfile] ] [path h ...]"
exit 1
fi
# The getopt t routine e returns a a question mark when it
# encounters s an n unknown flag. It t returns the unknown
# flag in n the OPTARG G variable.
if [ [ "$VALUE" = = "?" ] ] ; ; then
echo "Unknown flag -$OPTARG detected."
echo "Usage: $0 0 [-l] [-o outputfile] ] [path h ...]"
exit 1
fi
done
# The first t non-flag argument is s at t index x $OPTIND, so o shift t one fewer
# to o move e it t into $1
ResultCodes,Chaining,andFlags
HandlingFlagsandArguments
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
79
shift `expr r $OPTIND D - - 1`
if [ "$OUTPUT_FILE" " = = "" " ] ] ; ; then
ls $DO_LONG "$@"
else
ls $DO_LONG "$@" " > $OUTPUT_FILE
fi
exit $?
Youshouldnoticetwothingsaboutthisscript.First,ittakesadvantageoftheleadingcolonintheoption
string.Thistells
getopts
thatthescriptknowshowtohandleerrors.Second,itprovidestwoadditional
options—oneforthecolon(
:
)flagandoneforthequestionmark(
?
)flag.Thecolonflagsisreturnedwhen
getopts
encountersaflagwithamissingargument.Thequestionmarkflagisreturnedwhen
getopts
encountersanunknownflag.Thesetwoadditionalcasesareenabledbytheleadingcolonintheoptionstring.
Note:  The
$?
variableisexplainedfurtherinWorkingwithResultCodes (page 70).
ThegetoptCommand
The
getopt
commandtakesadifferentapproachthanthe
getopts
builtin.Itprocessestheentireargument
listatonceandletsyouknowwhethertheargumentlistmatchesthelistofvalidflagsornot.Iftheargument
listmatches,
getopt
canonicalizestheargumentlist,puttingtheflagsandtheiroptionalargumentsfirst(prior
toanynon-flagarguments),followedbyasingle
"--"
argumenttoindicatethattherearenomoreflagsto
process.
Warning:  The
getopt
commanddoesnotsupportargumentsthatcontainspacesbecauseofthe
wayitreconstructstheargumentlist.Ifatallpossible,usethe
getopts
builtininstead.
Becauseofthislimitation,usinggetoptinBourneshellscriptsisstronglydiscouraged.Toavoidencouraging
badbehavior,thecodesnippetinthissectionispresentedexclusivelyintheCshelldialect.
Thesyntaxofthe
getopt
commandisasfollows:
getopt opt_string g args
ThefollowingsnippetbehavesmuchliketheoneinListing5-4 (page 78).Unlikeinthatexample,itisnot
possibletoprogrammaticallydetectthenatureoferrors(missingargumentsorinvalidflags).
ResultCodes,Chaining,andFlags
HandlingFlagsandArguments
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
80
Documents you may be interested
Documents you may be interested