The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to cut a text file at a certain spot? LordJezo Shell Programming and Scripting 2 2 Weeks Ago 09:10 AM
Bringing your photos from F-Spot to the Web iBot UNIX and Linux RSS News 0 05-02-2008 08:50 AM
Logrotate problems - Can anyone spot the problem please?! anderow UNIX for Dummies Questions & Answers 10 01-10-2008 05:56 PM
Add a line to a specific spot in a file d__browne UNIX for Advanced & Expert Users 6 12-07-2006 04:52 AM
Spot karine UNIX for Advanced & Expert Users 1 02-08-2005 02:18 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-31-2006
Registered User
 

Join Date: Jul 2006
Posts: 18
Spot the difference

I posted earlier with a problem it's here, I have edited the script a little and it tells me once more that the end of line is unexpected and I'm really lost with this one, thanks for any help.

The new version:

#!/bin/sh
case $# in
0) echo "Usage: enshar filename1 filename2 [...]" >&2
;;
*) for file
do
if [ -d $file ]
then echo "enshar: $file is a directory" >&2
elif [ ! -f $file ]
then echo "enshar: $file does not exist" >&2
elif [ ! -r $file ]
then echo "enshar: $file is not readable" >&2
elif [ -h $file ]
then echo "enshar: $file cannot enshar" >&2
exit n
else
echo "\!EnShAr!\"
set '"cksum" $file'
"test $1 = nnnnnnnnnn || echo $0: bad cksum in $file << '\!EnShAr!\'"
cat $file
fi
done
;;
esac
Reply With Quote
Forum Sponsor
  #2  
Old 07-31-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,297
Use code tags!!
Code:
#!/bin/sh

if [ $# -eq 0 ] ; then
  echo "Usage: enshar filename1 filename2 [...]" >&2
  exit 1
fi
for file in "$@"
do 
    if [ -d $file ]
    then 
         echo "enshar: $file is a directory" >2    
         exit 1
    elif [ ! -f $file ]
    then 
         echo "enshar: $file does not exist" >2
         exit 1
    elif [ ! -r $file ]
    then 
         echo "enshar: $file is not readable" >2
         exit 1
    elif [ -h $file ]
    then 
         echo "enshar: $file cannot enshar" >2 
         exit 1
    fi
    cksum $file| read ck summy1 dummy2   # ck is the checksum
    echo "\!EnShAr!\ " 
    # no idea what this line is doing.   $1 cannot be used here and << makes no sense to me
    # try writing this out, not as script, but as what you want done here...
    "test $file = nnnnnnnnnn || echo $0: bad cksum in $file << '\!EnShAr!\'"
    cat $file
done
Reply With Quote
  #3  
Old 07-31-2006
Registered User
 

Join Date: Jul 2006
Posts: 18
Hi, I am trying to check the file is good, can you show me how this section would be done properly but I want the same format output as originally stated, thanks for any help
Reply With Quote
  #4  
Old 07-31-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,297
define "good" - it looks like you are writing a scripted front-end for shar....
Reply With Quote
  #5  
Old 07-31-2006
Registered User
 

Join Date: Jul 2006
Posts: 18
okay, i'm checking that the file is enshared correctly , that theres no proplems that have happened during it being not archived and then it being, not quite sure of the method you see, just been playing around with it but I have not got it to work correctly yet so wondered if there was someone who knew more about it then me, again thnks for any help offered
Reply With Quote
  #6  
Old 07-31-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,656
I can shed some light here. Look at your earlier code:
Code:
     echo "cat > $file <<\!EnShAr!"
              cat $file
              echo "!EnShAr!"
              echo "set `cksum $file`"
              echo "cksum" $file`
              check=$1
              echo "test $1 = $check || echo $0: Bad cksum in $file >&2 " >> shar
              echo "cat > $file <<\!EnShAr!" >> shar
This code is outputting another shell script. One shell script is writing a second shell script. The first 3 lines will output:
cat > /some/file/name <<!EnShAr!
contents of /some/file/name
!EnShAr!

In this context, that line: echo "!EnShAr!" makes perfect sense. You stripped out enough code that it is now useless. Put the script back the way it was. It was useful then.
Reply With Quote
  #7  
Old 08-02-2006
Registered User
 

Join Date: Jul 2006
Posts: 18
Hi, thanks for your help earlier, to my understanding this code looks like it should work and I'm very excited about it but the damn thing says the end of line 27 is unexpected, please help!

#!/bin/sh
case $# in
0) echo "Usage: enshar file [ ... ]" >&2
exit 1
;;
*) for file
do
if [ -d $file ]
then echo "enshar: $file is a directory" >&2
exit 3
elif [ ! -f $file ]
then echo "enshar: $file doesn't exist" >&2
exit 4
elif [ ! -r $file ]
then echo "enshar: $file can't be read" >&2
exit 5
elif [ -h $file ]
then echo "enshar: $file can't enshar" >&2
exit 6
else
echo "cat > $file <<\!EnShAr!\"
echo "!EnShAr!"
echo "set 'cksum $file'"
echo"cksum" $file
check=$1
echo "test $1 = $check || echo $0: bad cksum in $file >&2 " >> shar
echo "cat > $file <<\!EnShAr!" >> shar
fi
done
;;
esac

p.s, where should the "fi" be, thanks for any help
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:15 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0