Re: * wildcard in.sh script

2010-06-16 Thread Aiza

Polytropon wrote:

On Tue, 15 Jun 2010 09:25:05 -0700, Chip Camden sterl...@camdensoftware.com 
wrote:

As others have mentioned, you need to quote or escape the * in the
command line:

admin cell*


The problem, for explaination purposes, is that the shell you
enter the command will already expand cell* to cell_A, cell_B
and so on. This means that inside your script $1 will be assigned
the first matching entry, $2 would be the second one, $3 a third
one and so on.

To avoid this, you need to directly communicate the * to your
script's parameter $1, which is done by escaping or quoting it.
In this case, $1 will contain a literal * inside the script.

In most cases when scripting, it's useful not to assume such a
complicated command line processing. You better let the shell
do the expansion of *, so your script gets a lot of parameters,
one for each match, and you then continue to process them.

Another option is to just provide a prefix pattern to your
script, and let IT then add the * to expand it internally
within the script (i. e. by the shell that processes the
script). So you won't have to give a * at the command line
of the calling dialog shell.




Since I needed a wildcard character that was not already defined with 
special function that didn't have the be   on the command line, I 
experimented some and found the = sign. It works for me.


Thanks to everyone who replied.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: * wildcard in.sh script

2010-06-15 Thread Svein Skogen (Listmail Account)
On 15.06.2010 10:25, Aiza wrote:
 I have a directory with files in it. The first 3 letters of the file
 names is the group prefix. I'm trying to write a script to accept the 3
 letter of the group followed by a * to mean its a prefix lookup. But
 when I run it I get a message NO match that is not issued by the
 script. Its like * is not allowed as input.
 
 Looking for sample .sh code for handling this standard type of lookup or
 some online tutorial that has sample code for bourne shell programming.
 
 .

Just for the fun of it. Try escaping the asterisk (\*) and see if that
works?

//Svein

-- 
+---+---
  /\   |Svein Skogen   | sv...@d80.iso100.no
  \ /   |Solberg Østli 9| PGP Key:  0xE5E76831
   X|2020 Skedsmokorset | sv...@jernhuset.no
  / \   |Norway | PGP Key:  0xCE96CE13
|   | sv...@stillbilde.net
 ascii  |   | PGP Key:  0x58CD33B6
 ribbon |System Admin   | svein-listm...@stillbilde.net
Campaign|stillbilde.net | PGP Key:  0x22D494A4
+---+---
|msn messenger: | Mobile Phone: +47 907 03 575
|sv...@jernhuset.no | RIPE handle:SS16503-RIPE
+---+---
 If you really are in a hurry, mail me at
   svein-mob...@stillbilde.net
 This mailbox goes directly to my cellphone and is checked
even when I'm not in front of my computer.

 Picture Gallery:
  https://gallery.stillbilde.net/v/svein/




signature.asc
Description: OpenPGP digital signature


Re: * wildcard in.sh script

2010-06-15 Thread Fbsd1

Svein Skogen (Listmail Account) wrote:

On 15.06.2010 10:25, Aiza wrote:

I have a directory with files in it. The first 3 letters of the file
names is the group prefix. I'm trying to write a script to accept the 3
letter of the group followed by a * to mean its a prefix lookup. But
when I run it I get a message NO match that is not issued by the
script. Its like * is not allowed as input.

Looking for sample .sh code for handling this standard type of lookup or
some online tutorial that has sample code for bourne shell programming.

.


Just for the fun of it. Try escaping the asterisk (\*) and see if that
works?

//Svein

Not in the script but on the command line. newjails rm2*  as input to 
the script.

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: * wildcard in.sh script

2010-06-15 Thread Matthew Seaman
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 15/06/2010 09:25:45, Aiza wrote:
 I have a directory with files in it. The first 3 letters of the file
 names is the group prefix. I'm trying to write a script to accept the 3
 letter of the group followed by a * to mean its a prefix lookup. But
 when I run it I get a message NO match that is not issued by the
 script. Its like * is not allowed as input.
 
 Looking for sample .sh code for handling this standard type of lookup or
 some online tutorial that has sample code for bourne shell programming.

It would be helpful if you could show us some code, so we can tell
exactly what you're trying to do.

It sounds like your problem is you'ld like to supply a globbing pattern
as an argument to your script, and then apply it within the script.  So
you'ld like to call the script something like this:

   $ myscript.sh -p globpattern filename

The trick there would be to enclose globpattern in quote marks, which
will cause it to be passed literally into the script, rather than your
interactive shell attempting to expand the pattern before starting the
script and passing the arguments to it.  (That's a classic way of
getting a No match error message which seems to come from a program
that couldn't have generated it)

Note that it's not just the shell that can do globbing expansions --
find(1), pkg_info(1) are two examples I can think of immediately.  These
glob-pattern command line arguments similarly need quoting to protect
them from the shell.

Cheers,

Matthew

- -- 
Dr Matthew J Seaman MA, D.Phil.   7 Priory Courtyard
  Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate
JID: matt...@infracaninophile.co.uk   Kent, CT11 9PW
-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.14 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkwXQToACgkQ8Mjk52CukIxOrACggdei0bi8k13jyOg3tGQXyKp3
yFgAnjPJHivqt4VqM84UnGWqpFA/QQnR
=FwzT
-END PGP SIGNATURE-
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: * wildcard in.sh script

2010-06-15 Thread Aiza

Aiza wrote:
I have a directory with files in it. The first 3 letters of the file 
names is the group prefix. I'm trying to write a script to accept the 3 
letter of the group followed by a * to mean its a prefix lookup. But 
when I run it I get a message NO match that is not issued by the 
script. Its like * is not allowed as input.


Looking for sample .sh code for handling this standard type of lookup or 
some online tutorial that has sample code for bourne shell programming.






Here is the code

  prefix_name1=$1
  prefix_name2=`echo -n ${prefix_name1} | sed 's/*.*$//'`
  echo prefix_name1 = ${prefix_name1}
  echo prefix_name2 = ${prefix_name2}


  if [ ${prefix_name1} -nq ${prefix_name2} ]; then
  echo prefix_name2 = ${prefix_name2}
  fi
exerr hard stop


Here is the test and out put
# admin cell*
admin: No match.

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: * wildcard in.sh script

2010-06-15 Thread RW
On Tue, 15 Jun 2010 17:06:11 +0800
Aiza aiz...@comclark.com wrote:


 Here is the test and out put
 # admin cell*
 admin: No match.

try ./admin cell*
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: * wildcard in.sh script

2010-06-15 Thread RW
On Tue, 15 Jun 2010 12:20:14 +0100
RW rwmailli...@googlemail.com wrote:

 On Tue, 15 Jun 2010 17:06:11 +0800
 Aiza aiz...@comclark.com wrote:
 
 
  Here is the test and out put
  # admin cell*
  admin: No match.
 
 try ./admin cell*

Sorry that would be not found, not No match

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: * wildcard in.sh script

2010-06-15 Thread Aiza


This is the output. want to build list only containing
file names prefixed with job. Putting   around the value on the 
command line worked. But before this can go to production will have to 
fix the code so no   on the command value.


#  admin  job*
prefix_name1 = job*
prefix_name2 = job
 if job* != job
 list all1 = pen2
pen1
job_3
job_2
job_1
cell_B
cell_A
loop  = pen2
pen1
job_3
job_2
job_1
cell_B
cell_A*
hard stop


This is the code. From the results above the for is not looping 
through the file name list.


  dir=/usr/local
  prefix_name1=$1
  prefix_name2=`echo -n ${prefix_name1} | sed 's/*.*$//'`

  echo prefix_name1 = ${prefix_name1}
  echo prefix_name2 = ${prefix_name2}

  echo  if ${prefix_name1} != ${prefix_name2}
  if [ ${prefix_name1} != ${prefix_name2} ]; then

[ -d ${dir}/etc/jail/ ]  \
  cd ${dir}/etc/jail/  list=`ls | xargs rcorder`
echo  list all1 = ${list}
# know this worked because see it in the o/p

for jail in ${list}*; do
 echo loop  = ${jail}
 # this only shows first file name in the o/p
 # though the * on the for command would do globbing
done
  fi
exerr hard stop




___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: * wildcard in.sh script

2010-06-15 Thread Randal L. Schwartz
 Aiza == Aiza  aiz...@comclark.com writes:

Aiza This is the output. want to build list only containing file names
Aiza prefixed with job. Putting   around the value on the command
Aiza line worked. But before this can go to production will have to fix
Aiza the code so no   on the command value.

You can't fix your script to do that.  The expansion of '*' is a
function of the shell before it even gets to your script.  So this is
not possible.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: * wildcard in.sh script

2010-06-15 Thread Chip Camden
On Jun 15 2010 17:06, Aiza wrote:
 Aiza wrote:
 I have a directory with files in it. The first 3 letters of the file 
 names is the group prefix. I'm trying to write a script to accept the 3 
 letter of the group followed by a * to mean its a prefix lookup. But 
 when I run it I get a message NO match that is not issued by the 
 script. Its like * is not allowed as input.
 
 Looking for sample .sh code for handling this standard type of lookup or 
 some online tutorial that has sample code for bourne shell programming.
 
 
 
 
 Here is the code
 
   prefix_name1=$1
   prefix_name2=`echo -n ${prefix_name1} | sed 's/*.*$//'`
   echo prefix_name1 = ${prefix_name1}
   echo prefix_name2 = ${prefix_name2}
 
 
   if [ ${prefix_name1} -nq ${prefix_name2} ]; then
   echo prefix_name2 = ${prefix_name2}
   fi
 exerr hard stop
 
 
 Here is the test and out put
 # admin cell*
 admin: No match.
 

As others have mentioned, you need to quote or escape the * in the
command line:

admin cell*

You've also botched your regex (/*.*$/) -- it can't begin with a *.  What 
exactly
are you trying to match?

-- 
Sterling (Chip) Camden
http://camdensoftware.com | http://chipstips.com | http://chipsquips.com
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: * wildcard in.sh script

2010-06-15 Thread Polytropon
On Tue, 15 Jun 2010 09:25:05 -0700, Chip Camden sterl...@camdensoftware.com 
wrote:
 As others have mentioned, you need to quote or escape the * in the
 command line:
 
 admin cell*

The problem, for explaination purposes, is that the shell you
enter the command will already expand cell* to cell_A, cell_B
and so on. This means that inside your script $1 will be assigned
the first matching entry, $2 would be the second one, $3 a third
one and so on.

To avoid this, you need to directly communicate the * to your
script's parameter $1, which is done by escaping or quoting it.
In this case, $1 will contain a literal * inside the script.

In most cases when scripting, it's useful not to assume such a
complicated command line processing. You better let the shell
do the expansion of *, so your script gets a lot of parameters,
one for each match, and you then continue to process them.

Another option is to just provide a prefix pattern to your
script, and let IT then add the * to expand it internally
within the script (i. e. by the shell that processes the
script). So you won't have to give a * at the command line
of the calling dialog shell.




-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: * wildcard in.sh script

2010-06-15 Thread Aiza

Chip Camden wrote:

On Jun 15 2010 17:06, Aiza wrote:

Aiza wrote:
I have a directory with files in it. The first 3 letters of the file 
names is the group prefix. I'm trying to write a script to accept the 3 
letter of the group followed by a * to mean its a prefix lookup. But 
when I run it I get a message NO match that is not issued by the 
script. Its like * is not allowed as input.


Looking for sample .sh code for handling this standard type of lookup or 
some online tutorial that has sample code for bourne shell programming.





Here is the code

  prefix_name1=$1
  prefix_name2=`echo -n ${prefix_name1} | sed 's/*.*$//'`
  echo prefix_name1 = ${prefix_name1}
  echo prefix_name2 = ${prefix_name2}


  if [ ${prefix_name1} -nq ${prefix_name2} ]; then
  echo prefix_name2 = ${prefix_name2}
  fi
exerr hard stop


Here is the test and out put
# admin cell*
admin: No match.



As others have mentioned, you need to quote or escape the * in the
command line:

admin cell*

You've also botched your regex (/*.*$/) -- it can't begin with a *.  What 
exactly
are you trying to match?

As shown in the posted test results you can see that the * is removed 
from the input cell* and becomes cell and then cell* is compared to cell 
to determine if a search by prefix command was entered on the script 
command line. So the regex (/*.*$/) is working as coded as long as the 
script command line is coded like this cell*.

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org