14

In my .sh file I cannot invoke ant or mv or cp commands but the same commands executes on terminal.below is my script

sample.sh file

#! /bin/sh
cp filename.so filename_org.so
android update project -p .
ant clean
ant release

path added in .bashrc file.

export PATH=$PATH:/usr/bin/

cp, mv , ant are working only under terminal not via scirpt.

  • 1
    Give us more info about yur problem.. – Ruban Savvy Oct 20 '14 at 10:47
  • android / ant, are these binaries in /usr/bin? – UVV Oct 20 '14 at 11:38
12

As your script is a shell script (/bin/sh), then your PATH entries in .bashrc will not be read as that is for the bash (/bin/bash) interactive shell.

To make your PATH entries available to /bin/sh scripts run by a specific user, add the PATH entry to the .profile file in that users home directory.


Additionally you could add the full path for each of your commands within the script:

/bin/cp filename.so filename_org.so

Or set the PATH variable including all the required $PATHS at the beginning of your script.

PATH=$PATH:/bin:/usr/bin:xxx
export PATH
  • 2
    Correct analysis, but you didn't mention the right solution, which is to set PATH in the proper place instead of .bashrc. Changing the script to be a bash script will not make any difference: .bashrc is only loaded by interactive shells. – Gilles Oct 21 '14 at 21:34
2

Had the same issue while running a binary whose path is set in bashrc.

Solved the issue by doing the following:

Add the binary or add a link to the binary in /usr/bin.

ln -s [path_to_binary] [name_of_executable] 

Then check using

ls -l

You can remove the entry form bashrc.

0

you can do one simple thing if you have small script and finish your work asap

go on command line use below command

which your_command 

above command will print output including path use that command direct

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.