I don't know how to ask this clearly, so I'll try my best...
At what point does a shell script stop reading from a file, and begin using the buffered script?
Hopefully, this example will shed some light:
Now, if I execute this in the background, it will just wait for me.
During that time, if I edit tmp.sh, and uncomment the "Value Please" line, and comment out the "What is your value" line, it will continue with "What is your value".
If I comment out the "echo Lo" line, before I type "quit", the change is effective when the script completes.
As I understand it, the shells reads the loop into memory, and loops away... It doesn't seem to read the rest of the script in until I get to that part of the script...
Is there some documentation on this (as far as which circumstances will cause the shell to read ahead or not)?
I can provide other examples, if this one makes no sense (well, as much as it could, considering the silliness of a self-rewriting script, or the dangerous nature of modifying a script that is currently running....)
Dave Korn's book on ksh fully documents this behavior with respect to his shell. I am, of course, properly aghast that you would edit a running shell script. But this has implications with aliases which are processed when a command is read. I don't have the book in front of me, but here is an approximation of one of his examples:
This will print:
one
two
When I use aliases in a complex way, I will just fall back on eval. Replacing the first xxx command with "eval xxx" yields the expected result.
I'm not sure if I trust my memory on this, but I think that compound commands are read completely before execution. And, IIRC, so are dot scripts.
By editing a running script, you are going to stumble on two additional issues though. The first is buffering. I doubt very much that ksh issues individual read() system calls until it exactly acquires the last new line character that completes it's current compound command. Instead, I would guess that an unknown number of other characters have been pre-read into a buffer awaiting the next read. And this could easily be implementation dependent. The next problem is varying line length. You seem to be envisioning that ksh remembers the last line number read and somehow will resume with the line that follows. Instead ksh will be positioned on a byte number and will read the next byte. You could easily throw it into the middle of a line.
You seem to be envisioning that ksh remembers the last line number read and somehow will resume with the line that follows. Instead ksh will be positioned on a byte number and will read the next byte. You could easily throw it into the middle of a line.
Which makes sense, as I have seen it do some wierd stuff when playing with this the other day...
One of the first things we noticed (I wish I could remember what script we were playing with, since it exhibited this behavior), is that I could have a valid command, like "echo hello", that after changing, would cause the script to error out, complaining:
./tmp.sh: beho: command not found
We tried to control which bytes it overwrote, but were unable to control it in any usable manner...
Aliases are not expanded when the shell is not interactive, unless the
expand_aliases shell option is set using shopt (see the description of shopt under
SHELL BUILTIN COMMANDS below).
I never realized that before now. I guess it's since I can't think of a time when I've ever used aliases in a bash script...
In fact, I don't think I've ever used shopt before either, although I use disown every now and again...
So I am pretty new to the linux environment, and I am trying to create a shell that uses multiple pipes, and I read online that piping using shared memory space is more efficient than using regular piping. However, I have zero clue how to use shared memory space with pipes. Has anyone done this... (1 Reply)
Dear,
How to calculate %computational memory and %non computational memory from AIX server.
What command used to find out %computational memory and % non computational memory except topas.
Regards
Nowshath (1 Reply)
Hi!
Does someone know how to ensure that root user always will be able to login to a system?
What I mean is when a server is out of RAM and swapping like hell; sshd may spawn a shell and login root user to save the day? (2 Replies)
Hi everyone. I asked once here and it went well, so I'm very happy with this community.
I have a new question to ask. I would like to read&write specify memory of a process which is not the process I'm doing it from, nor a child nor a parent.
So, I want to do a program similar to Cheat... (3 Replies)
I have created and attached a shared memory segment. However I do not know how am I supposed to write and read data from it. I want to save various different data on this segment such as process IDs and other. Do you know how am I supposed to write these and be able to read such data in the correct... (1 Reply)
I created a shared memory and attached it. I also created the appropriate semaphores to sync. my read/write operations. However I do not know how am I supposed to do so. Anyone has got any ideas? I want to write int the form of 1234:23:444:... where each number between : means something to the... (0 Replies)
Hallo,
i need a Prompting read in my script:
read -p "Enter your command: " command
But i always get this Error:
-p: is not an identifier
When I run these in c-shell i get this error
/usr/bin/read: read: bad option(s)
How can I use a Prompt in the read command? (9 Replies)
I am looking for C program source code. Could you please help me in finding the source code required mentioned below.
program to create multiple threads (one master thread and rest worker threads) and using the threads write into and read from shared memory
Restrictions:
Only one thread... (2 Replies)