Bash can give unexpected results if one edits a script while the script is running. But it would often be very convenient to be able to edit a temporary copy of a script that I run within a shell, but make sure it is back in the original location before I run it again. Does anyone have suggestions for a workflow or customizations to Emacs to facilitate this?
The shell reads and executes commands one by one, so the simple answer is "yes, editing a running script can affect it", but it's important to understand the details. If you are careful, you can add lines to the end of a running script, and they will be run after the other commands already in the script.
Bash has evolved over the years taking code from ksh and sh . Adding #!/bin/bash as the first line of your script, tells the OS to invoke the specified shell to execute the commands that follow in the script. #! is often referred to as a "hash-bang", "she-bang" or "sha-bang".
Parallel executes Bash scripts in parallel via a concept called multi-threading. This utility allows you to run different jobs per CPU instead of only one, cutting down on time to run a script.
M-x delete-file
, press down
to insert obtain the path to the file you're editing, and RET
to delete the file. When you next save your buffer, this will create a new file. Bash will keep executing the old, deleted file.
By the way, in most cases, you don't even need to take this precaution. Emacs usually saves to a temporary file, then renames that temporary file to the proper file name (which deletes the old file, unless it's being kept as a backup). Emacs only overwrites the file in place if it detects that it can't recreate the file properly: if the file has hard links, or if you don't have write permission on the directory. (I'm simplifying a little; the details are in the basic-save-buffer-2
function in files.el
.) As long as the file has a single directory entry and you have write permissions on the directory containing the script, just press C-x C-s
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With