Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.misc > #7806

Re: Is bash.sh compiled or interpreted?

From Joe Beanfish <joebeanfish@nospam.duh>
Newsgroups comp.os.linux.misc, comp.os.linux.networking
Subject Re: Is bash.sh compiled or interpreted?
Date 2013-04-08 14:37 +0000
Organization A noiseless patient Spider
Message-ID <kjukmm$cpl$1@dont-email.me> (permalink)
References <kji2dk$cs2$1@dont-email.me>

Cross-posted to 2 groups.

Show all headers | View raw


On Wed, 03 Apr 2013 20:11:33 +0000, Avoid9Pdf wrote:
> My previous query has exposed much of my confusion.
> Pascal B's smpt.sh:-----------
> ...<initialise variables>
>   cat>$message
> (
>     read line 0<&3 ; $trace "$line">$log case "$line" in 2*) ;; *) echo
>     "QUIT" 1>&3 ; exit 0 ;; esac echo "HELO $local_name" 1>&3 read line
>     0<&3 ; $trace "$line">$log case "$line" in 2*) ;; *) echo "QUIT"
>     1>&3 ; exit 0 ;; esac echo "MAIL FROM: <${from}>" 1>&3
> ...
>     echo "QUIT" 1>&3
> ) 3<>/dev/tcp/$smtp_server/25 -----------------------
> 

() is a sub process. Very similar (but not identical) to having everything
in between in a separate script file and running
   otherscript 3<>/dev/tcp/$smtp_server/25
Read the bash man page section "Compound Commands"

Depending on desired side-effects that code could also be put into
a function then call that function instead of putting it inline. e.g.

dosmtp(){
  read line 0<&3 ...
}

cat >$message
dosmtp 3<>/dev/tcp/$smtp_server/25

> Is it right that FD3 is bound to "/dev/tcp/$smtp_server/25"
> only at the last line of the script, whereas FD3 is USED in previous
> lines;
> so that the complete script must be compiled before the <implementing
> code> is generated ?
> So that this presents a very unnatural mental model for users who are
> used to scientific or legal thinking, where the text can be confirmed as
> being valid at intermediate stages?

(), external command, and function call are all functional units that
may have their I/O redirected.

It doesn't help at all to debate the semantics of a language that's
been around for 30+. It works how it works and it's not going to change.
You have 2 choices:
  1) Learn to deal with how it works regardless of how you want it to.
  2) Move on.

> ----
> Per Joe Beanfish;
> cat>$message
>  means 'read from stdin and write that to File:message'.
>  
> Is this completed before the (instruction-sequence starts), because
> `read line` will use stdin?
> So what's the point of `cat>$message` ?
> Is it just to write a little introduction, before the actual task
> starts?

The "cat" is but one part of a larger script obviously. That script
is presumably given the mail message on stdin. Possibly like this
   somescript <someMessageFile
or
   somethingElse | somescript
or
   somescript
     (user types the message then hits ^D)
or
   etc.

cat >$message

will take all of that input and write it to the filename in $message.
Then processing will continue with the subsequent line(s).
In the snippet provided above the message saved in the file is not used.

> Do readers understand the WHOLE script as implementing a mail-client --
> other than just snippets?
> And how it would it be decomposed into testable parts?
> 
> What are possible successive refinement versions of test scripts for
> this task.  I.e the 'hello world model' must be used.
> Ie. each version must be stand-alone-complete, and extended by later
> versions.

This is what programmers do. You can't expect to be taught how to program
and debug on usenet. Read books or take a course.

Back to comp.os.linux.misc | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Is bash.sh compiled or interpreted? Avoid9Pdf@gmail.com - 2013-04-03 20:11 +0000
  Re: Is bash.sh compiled or interpreted? J G Miller <miller@yoyo.ORG> - 2013-04-03 21:10 +0000
    Re: Is bash.sh compiled or interpreted? The Natural Philosopher <tnp@invalid.invalid> - 2013-04-03 22:34 +0100
      Re: Is bash.sh compiled or interpreted? unruh <unruh@invalid.ca> - 2013-04-04 04:40 +0000
        Re: Is bash.sh compiled or interpreted? Allodoxaphobia <knock_yourself_out@example.net> - 2013-04-04 14:01 +0000
    Re: Is bash.sh compiled or interpreted? Avoid9Pdf@gmail.com - 2013-04-04 19:12 +0000
      Re: Is bash.sh compiled or interpreted? Richard Kettlewell <rjk@greenend.org.uk> - 2013-04-04 20:43 +0100
        Re: Is bash.sh compiled or interpreted? orcus@pwr.wroc.pl - 2013-04-05 03:43 +0000
          Re: Is bash.sh compiled or interpreted? Jerry Peters <jerry@example.invalid> - 2013-04-05 19:54 +0000
      Re: Is bash.sh compiled or interpreted? unruh <unruh@invalid.ca> - 2013-04-04 22:55 +0000
        Re: Is bash.sh compiled or interpreted? Richard Kettlewell <rjk@greenend.org.uk> - 2013-04-05 09:12 +0100
          Re: Is bash.sh compiled or interpreted? unruh <unruh@invalid.ca> - 2013-04-05 16:35 +0000
            Re: Is bash.sh compiled or interpreted? Richard Kettlewell <rjk@greenend.org.uk> - 2013-04-05 17:50 +0100
        Re: Is bash.sh compiled or interpreted? J G Miller <miller@yoyo.ORG> - 2013-04-05 16:02 +0000
          Re: Is bash.sh compiled or interpreted? Jerry Peters <jerry@example.invalid> - 2013-04-05 19:58 +0000
        Re: Is bash.sh compiled or interpreted? Unknown <dog@gmail.com> - 2013-04-05 19:44 +0000
          Re: Is bash.sh compiled or interpreted? Jerry Peters <jerry@example.invalid> - 2013-04-05 19:51 +0000
      Re: Is bash.sh compiled or interpreted? Surinder <Surinder.Singh@example.net> - 2013-04-09 11:20 +0530
  Re: Is bash.sh compiled or interpreted? Joe Beanfish <joebeanfish@nospam.duh> - 2013-04-08 14:37 +0000
    Re: Is bash.sh compiled or interpreted? Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2013-04-08 21:08 +0300

csiph-web