linux - Why does specifying my shell change the EUID of root? -
linux - Why does specifying my shell change the EUID of root? -
if specify shell /bin/bash in script, euid of root 0. if don't, , script runs in default shell (also /bin/bash), euid of root empty string! i'm new scripting , thought there no difference long bash ran show.
the code i'm running checks if programme run root, , restarts programme sudo if not.
#!/bin/bash echo euid = $euid echo shell = $shell if [ $euid -ne 0 ]; sudo "$0" exit $? fi
when run, see
euid = 1000 shell = /bin/bash euid = 0 shell = /bin/bash
but if remove she-bang line,
euid = 1000 shell = /bin/bash euid = shell = /bin/bash ./test.sh: 4: [: -ne: unexpected operator
the script runs in same shell 4 times, why deed differently when sudo calls without specifying /bin/bash?
i'm running ubuntu 14.04 if matters.
thanks in advance!
by removing shebang line, calling ubuntu default shell, dash, not bash.
dash not define $euid
, leading empty assignment. in fact, $euid
1 of many enhancements brought bash on posix standard. instead, dash meant small, fast , lightweight possible, , implements minimal set of features required standard.
you assert runs in same shell 4 times, in fact doesn't. environment variable $shell
not refer shell running current process; refers account's login shell, defined in /etc/passwd
or equivalent.
linux bash shell sudo ubuntu-14.04
Comments
Post a Comment