While attempting to write a simple bash script to help
with my deployment process, I ran in to a confusing error:
#!/bin/bash
WEEKDAY=$(date +'%u')
echo $WEEKDAY
DAYS_TO_WEDNESDAY=$((3-$WEEKDAY))
echo $DAYS_TO_WEDNESDAY
Results in:
1
")syntax error: invalid arithmetic operator (error token is "
The strangest part of it is that I c...
I run across many shell scripts with variables in all caps, and I've always thought that there is a severe misunderstanding with that. My understanding is that, by convention (and perhaps by necessity long ago), environment variables are in all-caps.
But in modern scripting environments like Bash, I have always prefered the convention ...
Bash uses readline, and readline can delete the word to the right of the cursor with "kill-word".
The problem is in recognizing the keypress of control-delete. When I press them in bash, "5~" is output on the screen. I could just bind for this, but it would mean that one day I need to type "5~", and it deletes a word to the right in...
I have a process that already started, with stdout to the console.
can I redirect it to a file, without restarting it?
...
Can someone please give me an example of using xargs on the below operation?
tar c $dir/temp/*.parse\
| lzma -9 > $dir/backup/$(date '+%Y-%m-%d')-archive.tar.lzma
I get the error from bash "/bin/tar: Argument list too long"
Particularily I am trying to do LZMA compression on about 4,500 files; so this isn't surprising. I just do...
It is not totally rigth that I can run a Bash function with 000 permissions, but almost. My code is:
#!/bin/bash
function hello {
echo Hello! }
The hello-file has permissions:
-r-------- 1 UnixBasics hello_file
Firtsly, I type with the current permissions:
$ . ./hello_file;hello
The tweak is to change the 400 permissions to 00...
I need something like a stacktrace in bash, is that possible?
A script is misbehaving. I need to know who calls that script, and who calls the calling script, and so on, only by modifying the misbehaving script.
What do you say?
...
I am creating temporary files from a bash script. I am deleting them at the end of the processing, but since the script is running for quite a long time, if I kill it or simply CTRL-C during the run, the temp files are not deleted.
Is there a way I can catch those events and clean-up the files before the execution ends?
Also, is there s...
This answer to a similar question proposes a 1-line method to timeout a long-running command from the bash command line:
( /path/to/slow command with options ) & sleep 5 ; kill $!
But it's possible that a given "long-running" command may finish earlier than the timeout. (Let's call it a "typically-long-running-but-sometimes-fast" comm...
We required a script that simulates Associative arrays or Map like data structure for Shell Scripting, any body?
...
In this answer to another question, I was told that
in scripts you don't have job control
(and trying to turn it on is stupid)
This is the first time I've heard this, and I've pored over the bash.info section on Job Control (chapter 7), finding no mention of either of these assertions. [Update: The man page is a little better, me...
In a comment on this answer of another question, the commenter says:
don’t use kill -9 unless absolutely
necessary! SIGKILL can’t be trapped so
the killed program can’t run any
shutdown routines to e.g. erase
temporary files. First try HUP (1),
then INT (2), then QUIT (3)
I agree in principle about SIGKILL, but the rest i...
As someone who did a lot of sh scripting twenty years ago, and now coming back to it again, I find I'm using techniques that are considered obsolete. I should take the time to read the "What's new", but I don't. and it's not terribly efficient. Examples:
Instead of use
tmpfile=/tmp/me$$ tmpfile=`mktemp`
[ ] ...
I have quite a few simple functions that I had previously kept in my .profile but I decided to put them in Perl scripts and add aliases to the Perl scripts. I feel like this is a bad idea, but the functionality looks/is better in Perl than bash since it is fairly complex (involving floating point math etc.).
Are there any best practices...
The title is rather more simplified than the functionality I am trying to express in a script.
I have a one-level deep directory tree (much bigger than example) which contain various content, although only two particular files are of interest to me. A file called 'current' and another called 'revisions'
- foo
|
|-> current
- ba...
Hi, I have the below command line argument which will print the output of aaa.sh to the screen while also writing stdout to bbb.out; however I would also like to write stderr to a file ccc.out. Any suggestions on how to modify the below piece? Thanks!
./aaa.sh | tee ./bbb.out
Update: stdout and stderr should still both be printed to ...
Hello, I have little problem with specifying my variable. I have a file with normal text and somewhere in it there are brackets [ ] (only 1 pair of brackets in whole file), and some text between them. I need to capture the text within these brackets in a shell (bash) variable. How can I do that, please?
...
How come I can do this in bash:
$ diff -u <(echo -e "line1\nline2") <(echo -e "line1\nline3")
--- /dev/fd/63 2009-03-30 09:49:07.527272646 +0100
+++ /dev/fd/62 2009-03-30 09:49:07.527272646 +0100
@@ -1,2 +1,2 @@
line1
-line2
+line3
i.e. I can use named pipes / process substituion to get the diff of a small chunk of text. However wh...
I have a python script that'll be checking a queue and performing an action on each item:
# checkqueue.py
while True:
check_queue()
do_something()
How do I write a bash script that will check if it's running, and if not, start it. Roughly the following pseudo code (or maybe it should do something like ps | grep?):
# keepalivescr...
I'm looking for a resource in python or bash that will make it easy to take, for example, mp3 file X and m4a file Y and say "copy X's tags to Y".
Python's "mutagen" module is great for manupulating tags in general, but there's no abstract concept of "artist field" that spans different types of tag; I want a library that handles all the ...