Showing posts with label Bash. Show all posts
Showing posts with label Bash. Show all posts

2010-10-05

The internal variable $! in Bash

Great use of a Internal variable in Bash

Using $! for job control:
possibly_hanging_job & { sleep ${TIMEOUT}; eval 'kill -9 $!' &> /dev/null; }
# Forces completion of an ill-behaved program.
# Useful, for example, in init scripts. 

2010-08-19

cat << EOF

Here is an option for writing several line of text to a file via a the shell.


~ # cat > test << EOF
> this is first line
> this is the second line
> EOF
~ # cat test
this is first line
this is the second line
~ #

Chain linux commands together

In the Linux shell you can chain a number of command together. You can do a number of command after each other without having to wait for each command to end.

e.g.
touch memtester ; memtester 16M 1 ; rm memtester

The commands is here separated with ; which tells the shell to execute the first command and then it is done it should execute the next command etc.

Another example:
touch memtester && memtester 16M 1 && rm memtester

Here the commands are separated with && which tells the shell to execute the first command and if it completes successfully then execute the next command and etc.