goer@ellis.uchicago.edu (Richard L. Goerwitz) (05/26/91)
It's not obvious to me how to take the value of the last argv element with /bin/sh, the way one can do with the C-Shell using subscripts. Perhaps an ignorant question, but how do? -- -Richard L. Goerwitz goer%sophist@uchicago.bitnet goer@sophist.uchicago.edu rutgers!oddjob!gide!sophist!goer
tmanos@wyvern.uucp (Tom Manos) (05/27/91)
goer@ellis.uchicago.edu (Richard L. Goerwitz) writes: >It's not obvious to me how to take the value of the last argv >element with /bin/sh, the way one can do with the C-Shell using >subscripts. Perhaps an ignorant question, but how do? >-- This works for me: #!/bin/sh eval echo '$'{$#} Should work for you, too. Break out TFM to understand how it works. Tom -- Tom Manos Norfolk, VA tmanos@wyvern (...!xanth!wyvern!tmanos) -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- I gotta get away from this day to day running around. Everybody knows this is nowhere. - Neil Young
gwyn@smoke.brl.mil (Doug Gwyn) (05/27/91)
In article <1991May25.204543.6428@midway.uchicago.edu> goer@ellis.uchicago.edu (Richard L. Goerwitz) writes: >It's not obvious to me how to take the value of the last argv >element with /bin/sh, the way one can do with the C-Shell using >subscripts. Perhaps an ignorant question, but how do? It's somewhat context sensitive, but here's one example: $ set -- a b c $ echo `eval echo $"$#"` c $
martin@mwtech.UUCP (Martin Weitzel) (05/28/91)
In article <16278@smoke.brl.mil> gwyn@smoke.brl.mil (Doug Gwyn) writes: >In article <1991May25.204543.6428@midway.uchicago.edu> goer@ellis.uchicago.edu (Richard L. Goerwitz) writes: >>It's not obvious to me how to take the value of the last argv >>element with /bin/sh, the way one can do with the C-Shell using >>subscripts. Perhaps an ignorant question, but how do? Yes, you're right, it's ignorant - especially ignorant of the FAQ posted monthly to this group (refer to question #32). >It's somewhat context sensitive, but here's one example: > $ set -- a b c > $ echo `eval echo $"$#"` > c But as Doug was already kind enough to post one possible solution, I'll post another (which happens to be my favorite as it works on ALL flavours of the bourne shell and with ANY number of arguments): for last do :; done Now the last argument is left in the shell variable last. -- Martin Weitzel, email: martin@mwtech.UUCP, voice: 49-(0)6151-6 56 83