Re: help, help scripting masters

From: Arthur Corliss <acorliss@nevaeh-linux.org>
Date: Mon Mar 22 2004 - 22:32:18 AKST

On Mon, 22 Mar 2004 captgoodnight@acsalaska.net wrote:

> Okay, I have a better way to ask my question, that is the problem here. Sorry. So,
> a simple idea, this is what I'm trying to basically do.
>
> #!/bin/sh
>
> workem_ ()
> {
> ls "$FOLDER"
> }
>
> case $1 in
> --folder|-f)
> FOLDER=`echo $2`
> workem_;;
> *) exit;;
> esac
>
>
> >$ ./test.sh -f folder\ with\ spaces
>
> no go
>
> >$ ./test.sh -f folder
>
> works

What version of shell are you using? This exact example that you gave works
just fine for me. Though I do have to wonder why you would execute a system()
call to assign $2 to FOLDER, when FOLDER=$2 would work the same (and without
the subshell).

> A big thank you if ya can make adjustments to that so as to make it work with spaces and crazies.
>
> Sometimes the idea works with spaces, usually not though. Crazy characters make it puke. Spaces and crazy characters are
> required in the real workem_ function, only to confirm that the folder exists, and to cd into it.
> Maybe I should try getopts instead.?

If your filesystem supports the characters, then quoting them should work just
fine (except, god forbid, for those filenames with actual quotes in them ;-).
I think you need to provide the following information for us to help:

  1) Version of shell you're using
  2) Every strange corner case that you can't get to work

Your code above should work in most circumstances, particularly those with
whitespace. If it doesn't it's got to be a problem with the interpreter
itself.

Check out this sample session:

  acorliss@bifrost:~/test$ cat test.sh
  #!/bin/sh

  workem_ ()
  {
  ls "$FOLDER"
  }

  case $1 in
  --folder|-f)
          FOLDER=`echo $2`
          workem_;;
  *) exit;;
  esac

  acorliss@bifrost:~/test$ mkdir "foo bar" foo
  acorliss@bifrost:~/test$ touch foo\ bar/got-it foo/no-go
  acorliss@bifrost:~/test$ ./test.sh -f foo\ bar
  got-it
  acorliss@bifrost:~/test$ ./test.sh -f "foo bar"
  got-it
  acorliss@bifrost:~/test$ ./test.sh -f foo
  no-go

My sh is just a symlink to /bin/bash in this case, though.

        --Arthur Corliss
          Bolverk's Lair -- http://arthur.corlissfamily.org/
          Digital Mages -- http://www.digitalmages.com/
          "Live Free or Die, the Only Way to Live" -- NH State Motto
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Mon Mar 22 22:31:53 2004

This archive was generated by hypermail 2.1.8 : Mon Mar 22 2004 - 22:31:53 AKST