and now for something completely different...
sometimes in a shell script you need to do stuff that modifies
the positional parameters ($@, $1,
$2, etc) from the cmdline, usually via the builtin
shift, maybe from using getopt(1) or similar.
for example, it's quite common to see the following in a shell script that parses cmdline flags with getopt
# parse cmdline options with getopt
TEMP=`getopt -o h123 -n $0 -- "$@"`
if [ $? != 0 ] ; then usage >&2 ; exit 1 ; fi
# overwrites $@ with getopt-generated/sanitized arguments
eval set -- "$TEMP"
# destructively iterates across $@
while true; do
case "$1" in
-h)
# handle option h
shift
;;
...
--)
shift
break
;;
esac
...
done
but sometimes you want to be able to restore the original
positional parameters later, or otherwise quote them in a manner
where they can be passed along to another script/function, log
them, embed them in a string/file, etc. you can't always just stash
them in another variable to use that later, because
"$@" has a special meaning to the shell that can't
otherwise be reproduced with another variable.
one way you could try to store/save them would be to save
the original copy of $@ and use eval set
-- later on to change it back to the saved variable. using a
slightly simplified version of the above:
#!/bin/sh
# save the cmdline
saved="$@"
echo original command line, $# arguments: "$@"
while test -n "$*"; do echo arg: "$1"; shift; done
echo mangled command line, $# arguments: "$@"
# restore the cmdline
eval set -- "$saved"
echo restored command line, $# arguments: "$@"
while test -n "$*"; do echo arg: "$1"; shift; done
and at first glance, it seems to work:
rangda[/home/sean] ./bad.sh one two three
original command line, 3 arguments: one two three
arg: one
arg: two
arg: three
mangled command line, 0 arguments:
restored command line, 3 arguments: one two three
arg: one
arg: two
arg: three
but you may run into problems when some parameters have spaces, or quotes:
rangda[/home/sean] ./bad.sh "1: one" "2: two"
original command line, 2 arguments: 1: one 2: two
arg: 1: one
arg: 2: two
mangled command line, 0 arguments:
restored command line, 4 arguments: 1: one 2: two
arg: 1:
arg: one
arg: 2:
arg: two
rangda[/home/sean] ./bad.sh "one's one"
original command line, 1 arguments: one's one
arg: one's one
mangled command line, 0 arguments:
./bad.sh: eval: line 12: unexpected EOF while looking for matching `''
or worse, shell meta characters:
rangda[/home/sean] ./bad.sh 'i wonder what `pwd` would do'
original command line, 1 arguments: i wonder what `pwd` would do
arg: i wonder what `pwd` would do
mangled command line, 0 arguments:
restored command line, 6 arguments: i wonder what /home/sean would do
arg: i
arg: wonder
arg: what
arg: /home/sean
arg: would
arg: do
the solution is to build up the saved value a bit more manually, single-quoting each parameter (which should prevent any unintended side effects of space/quotes/metacharacters), and escaping existing single quotes inside of parameters.
# escape any single quotes in an argument
quote(){
echo "$1" | sed -e "s,','\\\\'',g"
}
# save up a properly quoted/escaped version of "$@"
for arg in "$@"; do
saved="${saved:+$saved }'$(quote "$arg")'"
done
echo original command line, $# arguments: "$@"
while test -n "$*"; do echo arg: "$1"; shift; done
echo mangled command line, $# arguments: "$@"
# restore the cmdline
eval set -- "$saved"
echo restored command line, $# arguments: "$@"
while test -n "$*"; do echo arg: "$1"; shift; done
let's see how it behaves:
rangda[/home/sean] ./good.sh "1 one" "2: two"
original command line, 2 arguments: 1 one 2: two
arg: 1 one
arg: 2: two
mangled command line, 0 arguments:
restored command line, 2 arguments: 1 one 2: two
arg: 1 one
arg: 2: two
rangda[/home/sean] ./good.sh "one's one"
original command line, 1 arguments: one's one
arg: one's one
mangled command line, 0 arguments:
restored command line, 1 arguments: one's one
arg: one's one
rangda[/home/sean] ./good.sh 'i wonder what `pwd` would do'
original command line, 1 arguments: i wonder what `pwd` would do
arg: i wonder what `pwd` would do
mangled command line, 0 arguments:
restored command line, 1 arguments: i wonder what `pwd` would do
arg: i wonder what `pwd` would do
while not entirely pretty, it does to do the trick. i'd be interested to know if anyone has a better way of doing this (or if there are hidden problems in what i've posted above).
karrine steffans and mr marcus clips
bajalo videos pornos gratis
computer pranks screamers
winmugen character downloads
kinky twist braids
elyria municipal court
sonic download mugen
download club penguin money maker 2
oregon jail roster
travis barker famous stars and stripes
sample appology letter loss of child
alacranes para tu amor translation
difur polipodium leucotomos
pittsburghmills com marriott hotel
shaggy bob hair
photos of flavor love boots
angled bob haircut pictures
mexican donkey live show
lia sophia on line catalogue
stunna shades lyrics
shield season seven premiere
hiphopvideochicks com hoopz
painful lump on elbow with head
www levits furniture
louisa lytton naked
uil 2010 2011 biennial realignment
mugen metal sonic
examples of elegy poems
www revistafake com
gory car wreck photos
abc store liquor prices for nc
marvel vs capcom 2 mugen screenpack
astra hand grips
takagi ofuro
autotradersandiego com
hindi mein chudai
livehotdeals dunkin donuts
1990 hairstyles pictures
snowplow aftermarket manufacturing
pictures of stacked bob hairstyles
aksi melayu
free printable christmas stationery borders
low fade vs taper
staph on butt pictures
liebson and company
bill finch biography
conway tracking info
jovensitas follando gratis
csc lawyers incorporating service
chucke cheese s printable coupons
teen porn toplist cp
www cuyahogacountycommonpleascourt
treen building report
ann marie mathers michigan
con way trucking nj
mang xem phim nguoi lon online
medrol dose packs
cignateldrug com
tijuana donkey sex show
ar 15 ballistic chart
aksi melayu
free printable christmas stationery borders
low fade vs taper
staph on butt pictures
liebson and company
bill finch biography
conway tracking info
jovensitas follando gratis
csc lawyers incorporating service
chucke cheese s printable coupons
teen porn toplist cp
www cuyahogacountycommonpleascourt
treen building report
ann marie mathers michigan
con way trucking nj
mang xem phim nguoi lon online
medrol dose packs
cignateldrug com
tijuana donkey sex show
ar 15 ballistic chart
www kinectafederal credit union com
webkinz clothing recipies
las panochas peludas
rb reliabilt garage doors
you tube roy woods phone prank
crocodylus porosus antimicrobial peptide sequence
www visadpsgiftcard com wachovia
chris daughtery cd
8lb shoulder roast cook
shimano 200b5
free printable mlk worksheets kids
21119 2157 igniter
craftsman 24788355 tire
wenhair care product reviews
nephew tommy upright trash can
lds christmas lesson ideas
uterus exam pics
lanber shotguns gun
truth or dare xxx questions
cool one liner quotes
cherylcolesuckingdick.html
toplessblondes.html
lesbiangroup.html
xxxlivecamchat.html
jessicaalbablowjobvideo.html
nickcarternaked.html
simpsonshavingsex.html
alessandraambrosioandphotoandmovie.html
cocktoobig.html
pointedtits.html
lesbainsex.html
nonnudepictures.html
badassgirls.html
venusnude.html
cumdrenchedtits.html
electrosex.html
hotfuckingsex.html
katewinsletexposedpic.html
ashsucksmisty.html
adulthalloweenpartyideas.html
sidney crosby girlfriend said
hoang thuy linh scandal video download
www muggleston pitbullfarm
vera bradley outlets
main place mall santa ana cinema
terracotta pot crafts
how to make lean syrup cups
quinceanera hall decoration
coco austin rapper model
cursive letters tattoos
free unwanted club penguin account
wwe kelley kelly
cursive alphabet writing tattoos
canton spirituals lyrics site
pictures of fade haircut
printable alphabet bubble letters
www free religious skits for lent
fotos de pauline crespo desnuda
miley cyrus cheating on nick jonas
aragon mugen download
www pokemon crater combattle arena
tiffany pollard xxx
printable graffiti bubble letters
remington o u shotguns 310
carrie mythbusters nude
oj simpson murder crime scene
mugen hyper goku
judge maybelline ephraim
akon i wanna fuck you lyrics
www sbc software yahoo com
flashy default layouts
bergen county newspaper nj
coco austin website
tamagotchi v4 5 secret codes
jose luis torrents
outkast pitbulls dogs
phim online mien phi com
uptown comedy club atlanta ga
juanita bynum s wedding pictures
winn dixie employment application online
itp wheelsand tire combo
ductboard humidifier installation
audio sigma gamma rho chants
kia sedona idler pullies
tanguitas sexis hispanas
marshall university plane crash in 1971
flavor of love deelicious
edith bouvier beale biography
hudson belk clothing
1971 marshall football team record
gotti line pitbulls dogs
pee wee gonzalez layout
xem phim heo truc tuyen
winn dixie online applications
my dish olivegarden com
lia sophia jewlry spring 08 catalog
carrie underwood fakes
angel king model
vocab workshop level f answers
ngentot dengan sepupu
itp wheelsand tire combo
ductboard humidifier installation
audio sigma gamma rho chants
kia sedona idler pullies
tanguitas sexis hispanas
marshall university plane crash in 1971
flavor of love deelicious
edith bouvier beale biography
hudson belk clothing
1971 marshall football team record
gotti line pitbulls dogs
pee wee gonzalez layout
xem phim heo truc tuyen
winn dixie online applications
my dish olivegarden com
lia sophia jewlry spring 08 catalog
carrie underwood fakes
angel king model
vocab workshop level f answers
ngentot dengan sepupu
itp wheelsand tire combo
ductboard humidifier installation
audio sigma gamma rho chants
kia sedona idler pullies
tanguitas sexis hispanas
marshall university plane crash in 1971
flavor of love deelicious
edith bouvier beale biography
hudson belk clothing
1971 marshall football team record
gotti line pitbulls dogs
pee wee gonzalez layout
xem phim heo truc tuyen
winn dixie online applications
my dish olivegarden com
lia sophia jewlry spring 08 catalog
carrie underwood fakes
angel king model
vocab workshop level f answers
ngentot dengan sepupu
miley cyrus boyfriend fan site
benihana japanese restaurant washington dc
keisha knight pullman myspace page
marshall plane crash victims list
benny hanna menu
www bankofamerica com login
simile and metaphor powerpoint
karrine stephens book
nude ursula mayes
cody linley shirtless hoot
rube goldberg simple machine ideas
miley cyrus kiss nick jonas
gruesome pictures of dead bodies
demoulas market basket store locations
coupon for edible arrangements
kasam se meera
stride rite outlets
espin the bottel com
international harvester myspace layouts
kenya simmons aka new york
new reggaeton nota loka lyrics
pathological lying symptoms
florida dept of corrections
traceable alphabet letters
medium curled out bob
free fishing and hunting myspace layouts
evangelist marlon reid
shawty lo dun
zebra default layout
onces into ml
www youporn tv
truyen tranh nhuoi lon
lrg myspace layout
mocxi viet nam vuonmongmo
kazakhstan national anthem borat lyrics
quintanna didion dunne
ed cayce predictions
ellington mall bradenton
kristy alley nude
allen park mjr dollar show
new reggaeton nota loka lyrics
pathological lying symptoms
florida dept of corrections
traceable alphabet letters
medium curled out bob
free fishing and hunting myspace layouts
evangelist marlon reid
shawty lo dun
zebra default layout
onces into ml
www youporn tv
truyen tranh nhuoi lon
lrg myspace layout
mocxi viet nam vuonmongmo
kazakhstan national anthem borat lyrics
quintanna didion dunne
ed cayce predictions
ellington mall bradenton
kristy alley nude
allen park mjr dollar show
videoporndeevagreen.html
cumonhair.html
evalongoriaparkerhomesextape.html
nippleenlargement.html
giadadelaurentiistapeclip.html
asslovers.html
preteennudegalleries.html
gaynudist.html
videoporndeislafischer.html
throbbingcock.html
raylenefacial.html
jessicaalbapussy.html
michelleobamalesbiankiss.html
juliebenznewsextape.html
katdenningsnewsextape.html
fuckmywifeplease.html
giantdildoinsertion.html
freegaycams.html
hotsexvideos.html
youngblowjobs.html
videoporndeevagreen.html
cumonhair.html
evalongoriaparkerhomesextape.html
nippleenlargement.html
giadadelaurentiistapeclip.html
asslovers.html
preteennudegalleries.html
gaynudist.html
videoporndeislafischer.html
throbbingcock.html
raylenefacial.html
jessicaalbapussy.html
michelleobamalesbiankiss.html
juliebenznewsextape.html
katdenningsnewsextape.html
fuckmywifeplease.html
giantdildoinsertion.html
freegaycams.html
hotsexvideos.html
youngblowjobs.html
ashleyscottexposedvagina.html
jennajamesonpussy.html
konniehuqlesbianphoto.html
yugiohnaked.html
pamelaandersonsex.html
brittanysnowsextapedownload.html
danner52200bighornboots.html
finalfantasydoujin.html
veryyounggays.html
yunaxxx.html
hotgisellebundchenpicture.html
halleberrysexvideotape.html
xxxanimalsex.html
whitewifeblackstud.html
geeksgetthegirls.html
videosofgirlshavingsex.html
disneysex.html
camerondiaztarareidnude.html
tinysex.html
coedgirls.html