![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| sh -help with case statement (should be simple) | kuliksco | Shell Programming and Scripting | 1 | 11-19-2007 10:04 PM |
| case statement | bkan77 | Shell Programming and Scripting | 5 | 09-11-2007 05:54 PM |
| Case statement problem | gzs553 | UNIX for Advanced & Expert Users | 6 | 11-14-2006 04:24 PM |
| turning case into a if statement | brentdeback | Shell Programming and Scripting | 2 | 12-03-2005 12:12 AM |
| case statement | Bab00shka | Shell Programming and Scripting | 1 | 07-15-2002 05:31 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Case Statement
Can anyone please tell me why this wont work! Thanks so much!
#!/bin/sh for file do case $file in *.*.*) echo Cannot have more than 1 dot exit ;; *'**'*) echo Cannot have more than 1 asterisk exit ;; *'*'*|?.) echo this is a target ;; *) echo This is a file item = file ;; esac done if [! -e "$item"]; echo The File does not exit exit fi It just says Item not found? Thanks |
|
|||||
|
Two things. You write
Code:
if [! -e "$item"]; echo The File does not exit exit fi Code:
if [ ! -f "$item" ]; then echo "$item does not exist" exit fi You've also got spaces in your variable assignment, and no $ infront of the file variable name to reference it. You are, in effect, setting the value of item to "file". Another "no, no!" Do this Code:
item=$file Elaborate more on the script. What does it do? What is it for? And give the "proper" output from the script. Cheers ZB http://www.zazzybob.com |
|
||||
|
Hi Zazzybob, thanks for the help so far! Ok to elaborate more on what I am trying to do:
Well I'm trying to create a script that looks at parameters followed by a target that that specifies either a new main part of the file name or a new extension part but not both. Rename File1 File2 File3 *.html So File1 to File3 are params and *.html is is the target. Then with my loop Im trying to check the validity of them eg less than 2 params, cant have 2 dots, more than one asterisk and doesnt exist. Then If there are no errors the files are to be renamed in another loop. But I'm really struggling with it and Its really beginning to get on my nerves as I dont know what Im doing wrong! Any Suggestions on how I should do it would be fantastic. By the way, Im doing this becuase I have loads of files that I want to change extensions on and I want to do it this way because I've been trying for ages. Again many thanks. |
|
||||
|
Can anyone please help me (again) with this statement:
*'**'*) echo Cannot have more than 1 asterisk exit ;; As you can tell its supposed to drop out if there is more than 1 asterisk, but it doesnt! Many thanks. Also can anyone tell me what the structure of these statements are eg I know that * selects the whole string and ? selects a char. But how do I check if there are less than 2 parameters in my statements or if the parameter has to have a dot within the string! Thank you all so very much (I'm beginning to tear my hair out)! |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|