Upload Tizen:Base source
[external/bash.git] / examples / scripts / nohup.bash
1 #
2 # BASH VERSION OF nohup COMMAND
3 #
4 ctype()
5 {
6         path=$(builtin type -p $cmd | sed 1q)
7         if [ -n "$path" ]; then
8                 echo "$path"
9                 return 0
10         else
11                 case "$cmd" in
12                 */*)    [ -x "$cmd ] && { echo "$cmd" ; return 0; } ;;
13                   *)    case "$(builtin type -t $cmd)" in
14                         "")     return 1;;
15                         *)      echo "$cmd" ; return 0;;
16                         esac ;;
17                 esac
18         fi
19         return 1
20 }
21
22 trap '' HUP             # ignore hangup
23 command=$(ctype "$1")
24 oldmask=$(umask)
25 umask u=rw,og=          # default mode for nohup.out
26 exec 0< /dev/null       # disconnect input
27 if [ -t 1 ]; then       # redirect output if necessary
28         if [ -w . ]; then
29                 echo 'Sending output to nohup.out'
30                 exec >> nohup.out
31         else    echo "Sending output to $HOME/nohup.out"
32                 exec >> $HOME/nohup.out
33         fi
34 fi
35
36 umask "$oldmask"
37
38 # direct unit 2 to a file
39 if [ -t 2 ]; then
40         exec 2>&1
41 fi
42
43 # run the command
44 case $command in
45 */*)    exec "$@"
46         ;;
47 time)   eval "$@"
48         ;;
49 *)      "$@"
50         ;;
51 esac