SunQuest
           UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old September 6th, 2004, 03:00 PM
Katie Collier Katie Collier is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 4 Katie Collier User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Need help with parameter pattern matching

I have an assignment in for the day after tommorrow. I've been working on it solidly but i'm new to unix and am finding it difficult. Do you think you could tell me how i would write the equivalent of the third to last line

case $# in
0) echo no parameters;;
1) echo only one parameter.
echo put commands to be executed here.;;
*) echo more than one parameter.
echo enter code here.;;
esac

in a if statement. Need to write "if $file like * "
but cant seem to make it work. Any help would be extremely appreciated. Thanks guys, Katie

Reply With Quote
  #2  
Old September 6th, 2004, 05:36 PM
stevengs stevengs is offline
Permanently Banned
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Germany
Posts: 394 stevengs User rank is Lance Corporal (50 - 100 Reputation Level)stevengs User rank is Lance Corporal (50 - 100 Reputation Level)stevengs User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 3 Days 4 h 36 m 24 sec
Warnings Level: 10
Number of bans: 1
Reputation Power: 0
high katie,

don't quite understand the question. Can you expand on it a bit and post your attempts (code)?

Can name your shell/os?

-Steven

Am I jumping the gun Baldrick, or are the words "I have a cunning plan." marching with ill deserved confidence in the direction of this conversation? –Edmund Black Adder

Last edited by stevengs : September 6th, 2004 at 05:38 PM.

Reply With Quote
  #3  
Old September 6th, 2004, 06:05 PM
Katie Collier Katie Collier is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 4 Katie Collier User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Re: expand

Message Deleted

Reply With Quote
  #4  
Old September 6th, 2004, 06:23 PM
Katie Collier Katie Collier is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 4 Katie Collier User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Can I be totally honest. I have been given lots of assignments to do over the summer as my brother was lost in a traffic accident.
I have tried my hardest to complete them and left this one til last and now i don't have enough time. The code shown is my friends and I need to change it so it cant be recognised. I feel this is my only option.

Are they any ways to change the structure to make it look different while still doing the same thing. Heres my assign spec

Specification
~~~~~~~~~~~~~
Write a Bourne shell script called dosRename to implement an MS-DOS
style rename. The scripts parameters are file names followed by a
target that specifies either a new main part of the filename or a new
extension part of the filename but not both. Targets consist of three
parts: a dot, an asterisk and a string of filename characters. The dot
is the middle one of the three.


The command should check the validity of all the parameters before
renaming any files. If errors are found, the script should output an
error message and execute an `exit n'. The required error messages and
the values of `n' are as follows:

1 Usage: dosRename file [ ... ] target

2 dosRename: <parameter>: Can't have files after target

3 dosRename: <parameter>: Can't have two dots

4 dosRename: <parameter>: Can't have more than one asterisk

5 dosRename: <parameter>: Doesn't exist

6 dosRename: <parameter>: Must have a dot

7 dosRename: No target

Notes:

1 The first error message is given if the script is called with
less than two parameters.

2 <parameter> is a placeholder for the actual parameter.


If there are no errors in the parameters, the files are renamed with
the `mv' command. There is no need to check for existing files being
deleted; Unix is humble - it assumes the user knows best. For the
purposes of this assignment, there is no need to check for files that
can't be `mv'ed.

Reply With Quote
  #5  
Old September 6th, 2004, 07:36 PM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 49 m 57 sec
Reputation Power: 9
katie, it's not easy to automatize what you want, i wrote
3 month long a c-prog for this.
there are a lot of checks, parameter, fileperms, filetype, extensions, extension-syntax, filename globbing, is new name unique and and and....

a quick and very+very+very+very+very+very+very dirty way
be save: don't 'mv' but 'cp' and check status, it's slow and saver.

Code:
#!/usr/bin/sh

[ -d ${SAVE:=savemyoldfiles} ] || mkdir $SAVE || exit 1 # error
for file in `ls *old`
do
   [ -f $file ] || continue # not a plain file
   [ -s $file ] && continue # empty file
   cp $file $SAVE >/dev/null 2>&1 || continue  #error
   FILE=`echo $file|sed 's/old$/new'`
   cp $file $FILE >/dev/null 2>&1 || continue  #error
   rm $file
done


nota: [ xxx] && abc || ABC
is a shorthand of: if [ xxx ] ; then abc ; else ABC; fi
and is the brother of 'c': aaa = (xxx) ? abc : ABC;
just a style question.
remember the if-[elif-]else is maybe far the
most dangerous construct (in every languages)
if possible try something else: case, switch, for, do, while...
and if you use if, have a look
a) VAR=no; if[ xxx ] ; then VAR=yes; fi
b) VAR=no; [ xxx ] && VAR=yes
c) [ xxx ] && VAR=yes || VAR=no
d) if[ xxx ] ; then VAR=yes; else VAR=no; fi
all 4.expls are equivalent!

Last edited by guggach : September 6th, 2004 at 07:53 PM. Reason: typo

Reply With Quote
  #6  
Old September 7th, 2004, 04:41 AM
Katie Collier Katie Collier is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 4 Katie Collier User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanx babe, your an absolute star. Take care
luv Katie x

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Please can a really nice person help me.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway