![]() |
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 |
| cd from a Bourne Shell Script - Please Help | fawqati | Shell Programming and Scripting | 10 | 05-25-2006 03:26 AM |
| bourne script help | Heedunk | Shell Programming and Scripting | 1 | 02-05-2004 08:49 PM |
| simple bourne script | catbad | Shell Programming and Scripting | 2 | 03-24-2003 11:36 AM |
| Can i add colours to bourne Script ? | XXXXXXXXXX | Shell Programming and Scripting | 22 | 02-25-2002 05:27 AM |
| bourne shell script | psrinivas | Shell Programming and Scripting | 2 | 12-06-2001 03:38 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Bourne Script help
Hey guys,
I am trying to do a bourne script to look for c files in the current directory. I had it working where it finds the files and asks you to delete them or not, which works, but if there i no files, then it comes up with errors, which iam trying to get rid of. So I thought I would do a if else statement but failing miserably. The if statement is the problem and I want the filename in *.c to check if there is less than 1 but yeah. Any tips or ideas will be greatly appreciated. Code below: #!/bin/sh #Simple script to look for c programs. date=$(date) echo "Todays date is: $date" echo "This program will help delete all files ending with the .c extension" echo "Listing all files and the first 10 lines in each file now" for filename in *.c ; if [ filename in *.c -r] then echo "no files found" else do echo "=================================================================================================== ===============" echo "Variable filename is set to $filename..." ls -l $filename head -10 $filename done echo "Would you like to delete these files?" read YN case $YN in [yY]*) echo "Files deleted" rm *.c ;; [nN]*) echo "No files deleted." echo "Thanks for using this shellscript." ;; esac fi |
|
||||
|
what you can do here store the number of c files in a variable like this
no_of_files=`find . -name "*.c" -print | wc -l` echo $no_of_files do your manipulations in if condition with this. if $no_of_files -lt 0 then ------ else ------------ fi Thanks Namish |
|
||||
|
Hi thanks for the tips, it seems to have worked but now I just installed it as is and it does not get part the do part.
Todays date is: Thu Sep 6 18:15:04 EST 2007 This program will help delete all files ending with the .c extension Listing all files and the first 10 lines in each file now 0 delC.sh: line 19: syntax error near unexpected token `do' delC.sh: line 19: `do' Code below: #!/bin/sh #Simple script to look for c programs. date=$(date) echo "Todays date is: $date" echo "This program will help delete all files ending with the .c extension" echo "Listing all files and the first 10 lines in each file now" #for filename in *.c ; no_of_files=`find . -name "*.c" -print | wc -l` echo $no_of_files if $no_of_files -lt 0 then echo "no files found" else do echo "=================================================================================================== ===============" echo "Variable filename is set to $filename..." ls -l $filename head -10 $filename done echo "Would you like to delete these files?" read YN case $YN in [yY]*) echo "Files deleted" rm *.c ;; [nN]*) echo "No files deleted." echo "Thanks for using this shellscript." ;; esac fi Any ideas? Last edited by Pits; 09-06-2007 at 04:17 AM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|