I wrote a short C++ program that only receives an input value (basically cin >> a ;). I enabled UID on it. So ls -l shows:
-rwsr-xr-x 1 root root 6058 Sep 15 09:50 prog
Now I executed it as "test" user and checked the real vs. effective UID as under:
ps -eo cmd,ruser,euser,ruid,euid,pid | grep prog | grep -v grep
./prog test root 501 0 14251
Just as I expected, real userid is 501(test) and effective uid is 0(root).
So far so good.
Now I tried to do the same using a shell script. A bash script called script which should do the same thing but it doesn't. Why? Is there a way to see it working in a shell script.
-rwsr-xr-x 1 root root 5 Sep 15 09:29 script
ps -eo cmd,ruser,euser,ruid,euid,pid | grep 14328
bash test test 501 501 14328
Second, will the script work as root or as user test?