LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 12:28 PM   #1
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,803

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
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, 01:09 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
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, 02:04 PM   #3
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,803

Original Poster
Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
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, 05:39 PM   #4
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

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

Rep: Reputation: 196Reputation: 196
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 05:42 AM.
 
  


Reply



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 05: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 02:15 PM
[SOLVED] Odd Shell History Behavior Woodsman Slackware 3 12-07-2009 01:23 PM
postgresql odd behavior doublefailure Linux - Software 1 08-28-2002 12:40 AM
RH 6.2 ... odd behavior jubal Linux - Networking 3 02-27-2001 09:04 AM

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

All times are GMT -5. The time now is 06:54 AM.

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
Open Source Consulting | Domain Registration