[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Script doesn't work when it is run using '#!/bin/sh'



I have a number of bash scripts that work perfectly fine on fedora 23, but do not work on debian 8. I've tried to sort it out myself, but am a little stuck now hopefully someone is able to give me a nudge in the right direction.

Ideally I would like them to work on both.

On Fedora 23
$ ls -l /bin/sh
lrwxrwxrwx. 1 root root 4 Jan 11 11:02 /bin/sh -> bash
$ echo ${BASH_VERSION%%[^0-9.]*}
4.3.42

On Debian 8
$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Nov  8  2014 /bin/sh -> dash
$ echo ${BASH_VERSION%%[^0-9.]*}
4.3.30

As I discovered they weren't using the same bash, so I changed over my scripts to use #!/bin/bash and thought my problem would be solved, this doesn't seem to be the case, some errors have gone but some still remain.

I have shortened the script and pasted it below, its the IF part which is failing on debian 8.

#!/bin/bash

clear;
devSite="/home/admin/web/";

for domainDir in $(find ${devSite} -maxdepth 1 -type d); do

if [[ $domainDir == $devSite || $(basename ${domainDir}) == 'site1' || $(basename ${domainDir}) == 'site2' ]]; then continue; fi;

    echo "";
echo "Setting current directory to '$(basename ${domainDir})' web public folder.";
    cd ${domainDir}/web/public;

done;

The output I get from the above script is
wordpress_beta.sh: 8: bashtest.sh: [[: not found
wordpress_beta.sh: 8: bashtest.sh: web: not found
wordpress_beta.sh: 8: bashtest.sh: web: not found

Setting current directory to 'web' web public folder.


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus


Reply to: