LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices


Reply
  Search this Thread
Old 12-01-2019, 01:28 PM   #1
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: Currently: openSuSE, Raspian, Slackware. Formerly: CentOS, MacOS, Red Hat. Other: Solaris, Tru64
Posts: 1,597

Rep: Reputation: 189Reputation: 189
Odd shell -- or shell script -- behavior


I've been writing code for a long time but I can't say that I've ever encountered this until today...

I have a bash script that reads large datasets and extracts information out to a files that I'll be converting to a different format later. I kicked off the script a while ago and, while it was running, decided to edit the script and add
Code:
 mplayer -quiet read.wav completed.wav
to the very end so I would know when it was done. (It can take maybe 10 minutes to run so I'll multitask while it's grinding away.) At least, I thought, on the next run I'd get an audible indication that it was done and I could go on to the next run.

The weird thing is that the audible announcement came at the end of the run that was in progress -- and not yet completed -- when I finished with the edit to the script.

I would expected that the run in progress would complete silently and that the mplayer line would not have been "seen" until the next time the script was run.

Has anyone else noticed this?

The seems to be a new behavior. It looks like I'll need to be careful when making edits from here on.
 
Old 12-01-2019, 02:09 PM   #2
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.7.1908
Posts: 4,087

Rep: Reputation: 1391Reputation: 1391Reputation: 1391Reputation: 1391Reputation: 1391Reputation: 1391Reputation: 1391Reputation: 1391Reputation: 1391Reputation: 1391
I don't think that's unusual at all.

If the long-running process runs in a sub-shell, the script you were editing was just waiting for the sub-shell to return to it.
When it did, it continued and included the new code you'd added and saved.
 
Old 12-01-2019, 03:04 PM   #3
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: Currently: openSuSE, Raspian, Slackware. Formerly: CentOS, MacOS, Red Hat. Other: Solaris, Tru64
Posts: 1,597

Original Poster
Rep: Reputation: 189Reputation: 189
Quote:
Originally Posted by scasey View Post
I don't think that's unusual at all.

If the long-running process runs in a sub-shell, the script you were editing was just waiting for the sub-shell to return to it.
When it did, it continued and included the new code you'd added and saved.
Well that does make some sense. The script is a wrapper for a C program---the part that does all the heavy lifting. I would have expected some caching to have taken place so that the script that running had already been read and the disk copy wouldn't be touched again until it was re-run.

I suppose having shifted to mainly Perl scripts years ago (and, recently, to Python) I've gotten used to the way they execute. There have been many instances where I ran a lengthy Perl script, saw something goofy about a messages it was issuing, decide those were not quite what I wanted, and decide to edit the script right then. Never do I recall seeing the revised messages appear until the next time the script was run.

I think this harkens back to a discussion thread a little while ago about compiled vs. interpreted languages. I guess this experience is indication that shell scripts really do get read a line at a time and that the main bash process is keeping track of what line it's on before going back to the disk image and reading the next line. Probably easy to test this (though maybe later).

Now I'm off to consider what sort of crazy things you could do with self-modifying shell scripts. :^D

Cheers...
 
Old 12-01-2019, 06:39 PM   #4
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.7.1908
Posts: 4,087

Rep: Reputation: 1391Reputation: 1391Reputation: 1391Reputation: 1391Reputation: 1391Reputation: 1391Reputation: 1391Reputation: 1391Reputation: 1391Reputation: 1391
An strace of your script might be enlightening -- to you, that is.
I'm not suggesting you post it
 
Old 12-04-2019, 06:29 AM   #5
Geist
Member
 
Registered: Jul 2013
Distribution: Slackware 14 / current
Posts: 125

Rep: Reputation: Disabled
If you're using a window manager with, dang, I forgot the name for it, alerts? Like, xmonad, which I am using, has the option to point out a workspace and window in which an event has happened.

If you are using such a window manager, then you could change the PS1/Status of your shell to always add a bell to it, so background terminals will alert you when they're done.
I have this in my zshrc, for example
Code:
function precmd () (
   echo -en '\a';
)
My audio bell is switched off, or I'd probably be annoyed, but otherwise I have grown to really like this.
Usually, WMs are smart enough to not nag you when the window is focused already, too. So, that's a nice bonus.

Edit:
To clarify:
The idea is to change the terminal prompt to add the bell character to it, which does not get printed, it just triggers the bell.
Since the prompt is given every time a task is completed, to, well, prompt for further input, you will therefore get a bell when a task is completed.
That way you'll always know when a background job is done, no matter how big or small.

Bash compatible way :
https://superuser.com/questions/2756...questions-read

Last edited by Geist; 12-04-2019 at 06:42 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux Script, Concatenation doing Odd Behavior Darrell22 Linux - Software 13 10-03-2019 06:42 AM
Odd situation with raid10 array, odd number of drives, and it took, can't regrow now Red Squirrel Linux - Software 9 08-08-2014 03:15 PM
[SOLVED] Odd Shell History Behavior Woodsman Slackware 3 12-07-2009 02:23 PM
postgresql odd behavior doublefailure Linux - Software 1 08-28-2002 01:40 AM
RH 6.2 ... odd behavior jubal Linux - Networking 3 02-27-2001 10:04 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > General

All times are GMT -5. The time now is 02:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration