bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

subshell vs. su and +e


From: BuraphaLinux Server
Subject: subshell vs. su and +e
Date: Sat, 21 Jul 2007 13:46:55 +0700

This script, when run as root, gives me this:

BLS #./psycho
+ umask 0022
+ mkdir /tmp/mindy
+ chown nobody.nobody /tmp/mindy
+ set +e
+ su -p nobody -s /sbin/bash
+ cd /tmp/mindy
+ shazbot is not a valid command
/bin/sh: line 6: shazbot: command not found
+ (( 0!=0 ))
+ echo 'should not ever get here'
should not ever get here
+ (( 0!=0 ))
+ set -e
+ exit 0

I expected this:

BLS #./psycho
+ umask 0022
+ mkdir /tmp/mindy
+ chown nobody.nobody /tmp/mindy
+ set +e
+ su -p nobody -s /sbin/bash
+ cd /tmp/mindy
+ shazbot is not a valid command
/bin/sh: line 6: shazbot: command not found
+ (( 127!=0 ))
+ echo 'nanu nanu'
nanu nanu
+ exit 1
+ (( 1!=0 ))
+ echo 'subshell detected an error and exited'
subshell detected an error and exited
+ exit 1

Obviously I don't understand what's going on very well.
How can I get my expected behavior with bash 3.2.017?

#! /sbin/bash
#
# example to run as root where I try to drop priveleges for
# stuff (like building a binary package for a distribution)
# /sbin/bash is a statically linked version of bash 3.2.017
# no command shazbot exists on my path
#
# turn on error crashing and tracing
set -e -x
umask 0022
# do root stuff here
mkdir /tmp/mindy
chown nobody.nobody /tmp/mindy
# turn off error crashing
set +e
su -p nobody -s /sbin/bash << EOF
export HOME=/tmp
# turn off error crashing and turn on tracing
set +e -x
# begin the non-root stuff here
cd /tmp/mindy
shazbot is not a valid command
if ((${?}!=0))   # <--- ${?} is zero here not 127 ?????
then
 echo "nanu nanu"
 exit 1
fi
echo "should not ever get here"
# end the non-root stuff here
EOF
if ((${?}!=0))
then
 echo "subshell detected an error and exited"
 exit 1
fi
# turn on normal error crashing
set -e
exit 0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]