]> git.ipfire.org Git - thirdparty/bash.git/blame - examples/scripts/nohup.bash
Bash-4.2 patch 45
[thirdparty/bash.git] / examples / scripts / nohup.bash
CommitLineData
ccc6cda3
JA
1#
2# BASH VERSION OF nohup COMMAND
3#
4ctype()
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
22trap '' HUP # ignore hangup
23command=$(ctype "$1")
24oldmask=$(umask)
25umask u=rw,og= # default mode for nohup.out
26exec 0< /dev/null # disconnect input
27if [ -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
34fi
35
36umask "$oldmask"
37
38# direct unit 2 to a file
39if [ -t 2 ]; then
40 exec 2>&1
41fi
42
43# run the command
44case $command in
45*/*) exec "$@"
46 ;;
47time) eval "$@"
48 ;;
49*) "$@"
50 ;;
51esac