Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2004
    Posts
    55

    Unanswered: Basic scripting question

    There was a time when I was doing a good amount of basic scripting. The k shell scripts I wrote were basic but they worked. Unfortunately I haven't been in a position to do any scripting for many years and I'd like to get back to it as I really enjoyed scripting.
    On top of that I have not been able to retrieve my old scripts.

    My question is this, the style I was doing was somewhat similar to a Cobol program in structure in that the script was split into sections (or paragraphs or functions or whatever the correct term is) in that there would be a central section of code and it would be sent to a particular section, do its thing and then return.

    Can anyone tell me if this style had a name? Am I talking about functions within a script. Can anyone point me to an example of a script written like this?

    Many thanks

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I suspect that you'd be much happier working with Perl, PHP, or something like them. Korn shell scripting is great compared to the other command languages from its heyday, but ksh has been eclipsed in my mind by the much more powerful scripting languages available today.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Do you mean something like this. I have shortened it so it may not run as is.
    Code:
    #!/bin/ksh
    #Convert Fax file to tiff and then to mime encoded
    fax(){
    if [ -r /u2/sheaf/$ATTACH ]
    then
    $TFBIN/fax2tif -sheaf /u2/sheaf/$ATTACH -compression none \
    -path ./`basename $ATTACH`.tif 1>/dev/null 2>/dev/null
    else
    fi
    $TFBIN/b64encod <./`/bin/basename $ATTACH`.tif
    fi
    }
    #Convert Tiff to mime
    tif(){
    $TFBIN/b64encod < $ATTACH
    }
    
    #Convert pdf file to mime encoded
    pdf(){
    $TFBIN/b64encod <$filename.pdf
    }
    #Convert eml file to mime encoded
    eml(){
    $TFBIN/b64encod <$HWD/$filename.eml
    }
    #convert ltr file to PS to PDF
    ltr(){
    cd /u2/email/eps
    ps2pdf $HWD/$filename.ps $HWD/$filename.pdf >/dev/null
    cd $HWD
    pdf
    }
    #convert PS file to PDF
    ps(){
    cd /u2/email/eps
    ps2pdf $HWD/$filename.ps $HWD/$filename.pdf >>/tmp/ps2pdf.log
    cd $HWD
    pdf
    }
    ################Begin process################
    IFS="~"
    read UID TO SUBJECT MEMO discard 
    IFS=" "
    HWD=`pwd`; export HWD
    TFBIN=/usr/bin/tfbin
    files="$*"
    for ATTACH in $files
    do 
    EXT=`echo $ATTACH|cut -d"." -f2`
    filename=`echo $ATTACH|cut -d"." -f1`
    $EXT #values pdf ps ltr fax tif eml
    done
    The code builds an email from a file containing "from~to~subject~memo"
    and command line variables for files to attach.
    so:
    Code:
     proc a1.pdf a2.tif a3.ltr a4.ps <to_from_input

  4. #4
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool

    Quote Originally Posted by SnowCrash7 View Post
    There was a time . . . E t c . . .

    Can anyone tell me if this style had a name? Am I talking about functions within a script. Can anyone point me to an example of a script written like this?
    Structured (or Modular) programming. <-- Click here.
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  5. #5
    Join Date
    Mar 2004
    Posts
    55
    Many thanks to all for the input.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •