0

I have a script that I want to use to start Android Studio easily. Here is the content of the script:

    #!/bin/sh
    echo "Script is working"
    /home/user/Desktop/android-studio/bin/studio.sh

I have made it executable using chmod +x, and it runs (I know because it prints the string).

However, it always tells me that the third line contains 'No such file or directory'. When I copy and paste the third line into terminal it works fine, and Optic Studio starts. What am I doing wrong?

I have looked at other answers such as:

Run bash script with sh and How to run sh file from another sh file

but they haven't helped.

Thanks.

cohara
  • 111
  • 3
  • 19
  • 1
    have you tried `sh /home/user/Desktop/android-studio/bin/studio.sh` – Amanuel Nega Mar 09 '18 at 17:28
  • @AmanuelNega it shouldn't matter if he can run it directly from the terminal. @cohara, if you run `ls /home/user/` in that third line, do you see what you expect? – kabanus Mar 09 '18 at 17:32
  • Also, did you mean it says no such file `studio.sh`, or could it be a line inside `studio.sh` throwing the error? – kabanus Mar 09 '18 at 17:34
  • Thanks Amanuel Nega and kabanus. Amanuel Nega, the problem is not with studio.sh, tht works fine when I run it manually. kabanus, no I don't get what I expect when I run /home/user. Instead I get the error: 'ls: cannot access '/home/user'$'\r': No such file or directory' – cohara Mar 09 '18 at 21:07
  • Just to add, commands such as ls and pwd do not work either (command not found). realpath works. My $PATH does contain /home/user/bin – cohara Mar 10 '18 at 10:11

1 Answers1

0

The problem is that the executor is not able to find the location. edit the run.sh file as :-

   #!/bin/sh
    echo "Script is working"
    cd /home/user/Desktop/android-studio/
    bin/studio.sh

the 'cd' command will route to the specific location. then run the shell file (run.sh) by:-

bash run.sh
james
  • 21
  • 3