process control

# lists jobs in current session $ jobs # start job 1 (sleeps for 200 seconds) $ sleep 200 # suspended job 1 using control-z [1] + Stopped sleep 200 # start job 2 (sleeps for 400 seconds) $ sleep 400 # suspended job 2 using control-z [2] + Stopped sleep 400 # lists jobs... Continue Reading →

Advertisements

Background process

There are multiple ways to place a program in background mode. Background mode is when the program runs and returns you the prompt back and the program is till running but it can be tied to the session or untied to the shell. The following scenario is when a process is tied to a shell:... Continue Reading →

ksh – Process

-- Get process id of current process $ echo $$ 6113 -- shows process id $ ps PID TTY TIME CMD 2050 pts/2 00:00:00 ps 6113 pts/2 00:00:00 ksh Useful when creating a unique temp file example TEMPFILE=/tmp/tmpfile.$$ -- Get process id of last background id $ sleep 10 & [1] 2078 $ echo $!... Continue Reading →

How to change unix prompt?

C-shell (csh) Example: set prompt="[%n@%m %c] \! %" oracle@localhost ~] 39 % In this above example sets prompt to display username, hostname, current working directory and history number. %n - username, %m - hostname, %c - pwd, \! - history number K-shell (ksh) Example: $ export PS1='$USER [$PWD] $ ' oracle [/home] $ In the... Continue Reading →

whereiz – find all version of a command

Using the following script it will find all version of a command in $PATH (from Unix Power Tools) $ cat /tmp/whereiz #!/bin/sh testx="test -x" fixpath="`echo $PATH | sed \ -e 's/^:/.:/' \ -e 's/::/:.:/g' \ -e 's/:$/:./'`" # echo $fixpath IFS=": " for command do where="" for direc in $fixpath do $testx $direc/$command && where="$where... Continue Reading →

Run a logout script in k-shell

By setting trap one can run a logout script when a k-shell is being terminated. The built-in command trap in k-shell allows one to customize shell when a signal is received. # Set to run $HOME/.logout script when shell is terminated $ trap '. $HOME/.logout' 0 # display list of signals setup $ trap trap... Continue Reading →

grep options

Here are some of the options that can be passed to grep: -l - Print filename if pattern found otherwise it doesn't print the filename, if found any one file exit status is 0, if not found in any files then 1 -n - Print line # where pattern was found -i - ignore case... Continue Reading →

Regular expression

One can use the regular expressions to match in vi, grep, sed and awk. [a-d] - Match one character with in a-d i.e. a, b, c, d [^a-d] - Match one character not in the range a-d \<test\> - Match whole word test test\> - Match words that ends with test \<test\> \1ing - Match... Continue Reading →

Arrays in ksh

# how to create a array and assign a list of values set -A fruit apples pears oranges banana # print the first element in the array print $fruit[0] # set a new value to element 1 $fruit[1]=watermelon # how to get number of elements in the array $ x[1]=5 x[2]=3 x[3]=6 x[11]=55 $ print... Continue Reading →

Blog at WordPress.com.

Up ↑