Unable to execute command in the Linux with an user

5,972

Try adding the full path to the binary in your script; execute it with: /bin/mkdir You can find the full paths to commands using which followed by the command. It will then return the full path of the command e.g:

$ which mkdir
/bin/mkdir

You could also set PATH for the environment in which the script is run by using export. To do this in the script add a line similar to this: export PATH=$PATH:/bin:/usr/bin:/path/to/whateverelse in the beginning of your script.

See http://www.cyberciti.biz/faq/unix-linux-adding-path/ for details.

Personally I would recommend just using the full path to binaries though.

Share:
5,972

Related videos on Youtube

Sulthan Ibrahim
Author by

Sulthan Ibrahim

Updated on September 18, 2022

Comments

  • Sulthan Ibrahim
    Sulthan Ibrahim almost 2 years

    Two scenarios here.

    Sudo rights are given for a particular group.

    a. A new user is created and is assigned to the group. b. Using this user, when we execute commands via shell script it is unable to execute any of the commands (eg., mkdir), it displays 'command not found' error. but

    a. When same command is executed in an open terminal it does execute and creates directories. Any idea about the same would be greatly helpful.

    Let me know if you need more information on this.

    • user2914606
      user2914606 over 10 years
      Why do you mention sudo? Sounds like a problem with the PATH to me.