Bash scripts not found. Maybe EOL issue?

Started by davidedp, April 15, 2016, 05:02:41 PM

Previous topic - Next topic

davidedp

I am facing a problem that is driving me crazy. In the past months I have been developing a project based on Chaos Calmer 15.05. My project has a lot of bash scripts that have always worked fine on the RT5350F. Today I compiled Chaos Calmer 15.05.01 for my RT5350F, I installed bash and the scripts don't work anymore. If I execute my script myscript.sh
#!/bin/bash
echo hello

I obtain:
-ash: ./myscript.sh: not found
I noticed two really strange facts that may help you guys understand what is going on:

1) if I change the first line from #!/bin/bash to #!/bin/sh the script is executed without errors. However bash seems to be properly installed. Below is the result of  opkg info | grep -A 6 -i bash:
Package: bash Version: 4.3.39-1 Depends: libc, libncurses Status: install user installed Architecture: ramips_24kec Installed-Time: 1460723598

2) If I open script.sh in notepad, the end of line is CRLF. I learnt to use the EOL conversion tool to convert CRLF to LF. I save the file, I close it. But I don't know why, when I open it again the end of line is still CRLF. It is like if something is keeping my scripts with the incorrect end of line.

Any help will be greatly appreciated

mike_s

#1
Just because you have bash installed, doesnt mean that its being used by the system.

From the output of your script:
Quote from: davidedp on April 15, 2016, 05:02:41 PM
-ash: ./myscript.sh: not found

When it tries to execute your script, its executing your script under ash, the default shell of Busybox and the OpenWrt base.  You can figure out which application is aliased to a command by executing the "which" console command.

> which bash
> which sh


If executing the command > which bash does not return anything, it means that it doesnt know where to find the bash executable.  Maybe try running "> find -name bash" and make sure that that is in your $PATH.  "> echo $PATH "




Ash should function similarly to bash so if you don't expressly need to use bash, then just alias bash to ash by creating a symlink from bash to ash.  This is the same mechanism that OpenWrt uses to alias ash to sh.  Bash is really huge and on a small system like the rt5350, its going to take up a lot of space that could be used for other things.

>ln -s /bin/ash /bin/bash

If for some reason you NEED bash, you can change your /etc/inittab file to point to bash instead of ash as the default shell.

JohnS

The other thing is that if you type
./myscript.sh

It needs to be executable (chmod +x myscript.sh)

John