1 2 3 4 5 6 7 8 9 10
#!/bin/bash set -e if [[ -z $1 ]]; then target="$PWD" else target="$1" fi user="$(stat -c %U "$target")" cd "$target" su "$user" -c "cd $PWD; bash"