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 and shell scripting languages 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 11-12-2008 12:10 PM
Bringing your photos from F-Spot to the Web iBot UNIX and Linux RSS News 0 05-02-2008 12:50 PM
Logrotate problems - Can anyone spot the problem please?! anderow UNIX for Dummies Questions & Answers 10 01-10-2008 08:56 PM
Add a line to a specific spot in a file d__browne UNIX for Advanced & Expert Users 6 12-07-2006 07:52 AM
Spot karine UNIX for Advanced & Expert Users 1 02-08-2005 05:18 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-31-2006
Dim-Wit Dim-Wit is offline
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
  #2 (permalink)  
Old 07-31-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,813
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

  #3 (permalink)  
Old 07-31-2006
Dim-Wit Dim-Wit is offline
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
  #4 (permalink)  
Old 07-31-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,813
define "good" - it looks like you are writing a scripted front-end for shar....
  #5 (permalink)  
Old 07-31-2006
Dim-Wit Dim-Wit is offline
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
  #6 (permalink)  
Old 07-31-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
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.
Closed Thread

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:53 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0