Hi all
I have a simple text file ./version containing a version number. Unfortunately, sometimes the version number in the file is followed by whitespaces and newlines like
1.1.3[space][space][newline]
[newline]
[newline]
What is the best, easiest and shortest way to extract the version number into a bash variable without the traili...
Does anyone know how I can read the first two characters from a file, using a bash script. The file in question is actually an I/O driver, it has no new line characters in it, and is in effect infinitely long.
...
I want to write a shell script that spawns several long-running processes in the background, then hangs around. Upon receiving SIGTERM, I want all the subprocesses to terminate as well.
Basically, I want a "master process".
Here's what I got so far:
#!/bin/sh
sleep 600 &
PID1="$!"
sleep 600 &
PID2="$!"
# supposedly this should kill...
I find grep's --color=always flag to be tremendously useful. However, grep only prints lines with matches (unless you ask for context lines). Given that each line it prints has a match, the highlighting doesn't add as much capability as it could.
I'd really like to cat a file and see the entire file with the pattern matches highlighted....
Is there an equivalent of the bash pushd/popd build in commands for the KSH?
For those who don't know what pushd and popd in bash do, here is the description from the man page
pushd [-n] [dir]
pushd [-n] [+n] [-n]
Adds a directory to the top of the directory stack, or rotates
the stack, making the new top of ...
I'm sure there is an answer to this in the manual to screen, but I can't find it!
I want the bash shell spawned by GNU screen to source in a file in addition to the .bashrc that it already runs.
I can't put a call to the file in .bashrc because on our site .bashrc files get regenerated automatically on login.
Any ideas?
EDIT:
I creat...
Today I first saw the potential of a partial accidental deletion of a colleague's home directory (2 hours lost in a critical phase of a project).
I was enough worried about it to start thinking of the problem ad a possible solution.
In his case a file named '~' somehow went into a test folder, which he after deleted with rm -rf... when ...
In bash, is there a way to chain multiple commands, all taking the same input from stdin? That is, one command reads stdin, does some processing, writes the output to a file. The next command in the chain gets the same input as what the first command got. And so on.
For example, consider a large text file to be split into multiple files...
I am writing some testing scripts and want to catch all error output and write it to an error log as well as all regular output and write that to a separate log. I am using a command of the form
cmd > output.file 2> error.file
The command I am writing test scripts for can cause a segmentation fault. When the command segfaults, bash s...
Hi,
I've been trying to figure out how to run a bash command in a new Max OS X Terminal.app window. As, an example, here's how I would run my command in a new bash process:
bash -c "my command here"
But this reuses the existing terminal window instead of creating a new one. I want something like:
Terminal.app -c "my command here"
Bu...
This one fails:
nice -n 10 exec "$JAVA" $JAVA_HEAP_MAX $NUTCH_OPTS -classpath "$CLASSPATH" $CLASS "$@"
this succeeds:
nice -n 10 java test
Does it mean can't combine nice and exec?
...
According to Wikipedia, the following is a very elegant bash fork bomb:
:(){ :|:& };:
How does it work?
...
This question is similar to http://stackoverflow.com/questions/373156/what-is-the-safest-way-to-empty-a-directory-in-nix
I'm writing bash script which defines several path constants and will use them for file and directory manipulation (copying, renaming and deleting). Often it will be necessary to do something like:
rm -rf "/${PATH1}"...
Both Wolfram Alpha and Bing are now providing the ability to solve complex, algebraic logic problems (ie "solve for x, given this equation"), and not just evaluate simple arithmetic expressions (eg "what's 5+5?"). How is this done?
I can read most types of code that might get thrown at me, so it doesn't really make a difference what yo...
Hi there, I am having some trouble with Python giving me a result I do not expect. Here is a sample code :
number = re.search(" [0-9] ", "test test2 test_ 2 333")
print number.groups()
number = re.search(" [[:digit:]] ", "test test2 test_ 2 333")
print number.groups()
In the first block I get an object returned but with nothing in it...
What's the best way to pad numbers when printing output in bash, such that the numbers are right aligned down the screen. So this:
00364.txt with 28 words in 0m0.927s
00366.txt with 105 words in 0m2.422s
00367.txt with 168 words in 0m3.292s
00368.txt with 1515 words in 0m27.238
Should be printed like this:
00364.txt with 28 words...
Possible Duplicate:
How can I capture the stdout output of a child process?
I'm running a cat-like program in bash from Python:
import os
os.system('cat foo.txt')
How do I get the output of the shell command back in the Python script, something like:
s = somefunction('cat foo.txt')
?
UPD: Here is a related threa...
Hy,
suppose you got many files in a folder and you want first to sort it in alphabetic order and then delete all files until a specific file (not including it).
So im searching for a function/command/script/whatever which takes one string as imput and the deletes all files until this file.
I thought of a simple bash-script:
for i in *...
Hi all,
First off, I know that ~/ is the home directory. CDing to ~ or ~/ takes me to the home directory.
However, cd ~X takes me to a special place, where X seems to be anything.
In bash, if I hit "cd ~" and hit tab, it shows a bunch of possible ~X options like ~mail and ~postgres and ~ssh. Going to those folders and doing a pwd sh...