Why is sudo bash different from regular bash

Posted by cyberjar09 on Ask Ubuntu See other posts from Ask Ubuntu or by cyberjar09
Published on 2012-11-24T04:15:25Z Indexed on 2012/11/24 5:19 UTC
Read the original article Hit count: 351

Problem description : I am using something called play framework in my development which requires me to make the python script play available in the path. Hence I create a symbolic link in /usr/local/bin ... Now I have written a shell script (call it status.sh) which calls this python script as follows : play status <some values here related to my app> &> /tmp/xyz.txt and this shell script then sends me the file via email. This works perfectly when I execute the script as follows ./script.sh. However when the script is executed as a cron expression everyday I get an output from stderr saying 'play: command not found'.

Hence I did some digging on my own and here are my findings :

  1. echo $PATH when I am on the shell shows that I have /usr/local/bin available to me hence I can successfully execute the command play status
  2. however when I type in sudo bash and then echo $PATH I do not have the path /usr/local/bin anymore. It is a limited set of folders (one of them being /usr/bin).

Q : Why this behavior ?! I fail to understand why the path is different. Also as a workaround would you suggest I do :

  • new symbolic link from /usr/bin to /usr/local/bin (what are the side effects of this?)
  • remove /usr/local/bin sym link altogether and only use /usr/bin
  • is there a convention that I am not following here for linking new programs and executing them from $PATH ?

Thanks.

© Ask Ubuntu or respective owner

Related posts about scripts

Related posts about environment-variables