#!/bin/bash
+chdir=0
kerberos=0
x11=0
while getopts ":kx" opt; do
case $opt in
+ c) chdir=1;;
k) kerberos=1;;
x) x11=1;;
esac
user="$1"; shift
if [ -z "$user" ]; then
- echo >&2 "Usage: become [-k] [-x] <user>"
- echo >&2 "Options: -k Delegate Kerberos credentials even if target user is not root."
+ echo >&2 "Usage: become [-c] [-k] [-x] <user>"
+ echo >&2 "Options: -c Stay in current directory even if target user is not root."
+ echo >&2 " -k Delegate Kerberos credentials even if target user is not root."
echo >&2 " -x Delegate X11 cookie even if target user is not root."
exit 1
fi
fi
if [ $uid = 0 ]; then
+ chdir=1
kerberos=1
x11=1
fi
echo >&3 ". $HOME/.bash_profile"
[ -f "$BECOME/all" ] && cat >&3 2>/dev/null "$BECOME/all"
[ -f "$BECOME/$user" ] && cat >&3 2>/dev/null "$BECOME/$user"
-echo >&3 2>/dev/null "cd - &>/dev/null"
+[ $chdir = 1 ] && echo >&3 2>/dev/null "cd - &>/dev/null"
exec 3>&-
dir=$(dirname "$0")