[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: is there such a thing as "bytecode" for bash scripts? à la java "bytecode"? ...



Shell scripts will also return to the source during execution, seeking
to the next line in the file and rereading it.

You will often see errors in executing shell scripts if you edit them
while they are running, because code has shifted around.

For example:
$ cat t.sh
#!/bin/bash

echo "bob"; sleep 1
echo "bob"; sleep 1

# etc, repeat the above several times

While that is executing, edit the file in place, changing all of the
occurrences of "bob" with 'tom" .  Using nvi, it rewrites to the same
inode, while sed creates a new one.  So (at least for bash), when
using vi, it picks up the changes mid-run, while sed, it continues
using the old version.

That actually surprised me.  I *thought* that bash would reopen the
file each time and pick up the new code in both cases.  I learned
something!

If you do the same thing in a loop:


while true; do
  echo "tom"
  sleep 1
done

It does not seem to reread.

But for a sourced file, it does not appear to reread the sourced file.

I did not try all variations, like functions and what not.

This is all likely documented, but spending less than 10 seconds in
bash's info doc, I did not find it.  But this is all probably by POSIX
spec.  Just not awake enough yet to figure out good search terms.

I wouldn't be surprised if, in the early days, with limited disk
space, self modifying Bourne shell scripts was a feature.  I believe
it was Ken Thompson who stated "The steady state of disks is 'full'."

mrc


Reply to: