Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.user > #166765 > unrolled thread
| Started by | Aero Maxx <aero.maxx.d@gmail.com> |
|---|---|
| First post | 2016-04-16 14:30 +0200 |
| Last post | 2016-04-17 18:00 +0200 |
| Articles | 9 — 6 participants |
Back to article view | Back to linux.debian.user
Script doesn't work when it is run using '#!/bin/sh' Aero Maxx <aero.maxx.d@gmail.com> - 2016-04-16 14:30 +0200
Re: Script doesn't work when it is run using '#!/bin/sh' <tomas@tuxteam.de> - 2016-04-16 15:10 +0200
Re: Script doesn't work when it is run using '#!/bin/sh' David Wright <deblis@lionunicorn.co.uk> - 2016-04-16 16:20 +0200
Re: Script doesn't work when it is run using '#!/bin/sh' "Thomas Schmitt" <scdbackup@gmx.net> - 2016-04-16 16:30 +0200
Re: Script doesn't work when it is run using '#!/bin/sh' Aero Maxx <aero.maxx.d@gmail.com> - 2016-04-16 16:50 +0200
Re: Script doesn't work when it is run using '#!/bin/sh' Gene Heskett <gheskett@shentel.net> - 2016-04-16 17:40 +0200
Re: Script doesn't work when it is run using '#!/bin/sh' Jeremy Nicoll <jn.ml.dbn.25@letterboxes.org> - 2016-04-16 22:40 +0200
Re: Script doesn't work when it is run using '#!/bin/sh' Gene Heskett <gheskett@shentel.net> - 2016-04-17 01:20 +0200
Re: Script doesn't work when it is run using '#!/bin/sh' <tomas@tuxteam.de> - 2016-04-17 18:00 +0200
| From | Aero Maxx <aero.maxx.d@gmail.com> |
|---|---|
| Date | 2016-04-16 14:30 +0200 |
| Subject | Script doesn't work when it is run using '#!/bin/sh' |
| Message-ID | <roxwl-3jH-5@gated-at.bofh.it> |
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
[toc] | [next] | [standalone]
| From | <tomas@tuxteam.de> |
|---|---|
| Date | 2016-04-16 15:10 +0200 |
| Message-ID | <roy93-3Uq-9@gated-at.bofh.it> |
| In reply to | #166765 |
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sat, Apr 16, 2016 at 01:22:09PM +0100, Aero Maxx wrote: > 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. > 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. The [[ is correct bash syntax. To try to pinpoint the problem, try running the script with "bash <script>". If you don't want to run the script but just to check syntax, you might want to try "bash -n <script>". If that works out OK, perhaps your script is still being invoked under dash? regards - -- t -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlcSOWoACgkQBcgs9XrR2kbkrACeKm6V/h6Pg09eR6p4tq8RrB86 DyoAn1G8mKdveQibSGpX1Js1urzJwqC5 =HBl9 -----END PGP SIGNATURE-----
[toc] | [prev] | [next] | [standalone]
| From | David Wright <deblis@lionunicorn.co.uk> |
|---|---|
| Date | 2016-04-16 16:20 +0200 |
| Message-ID | <rozeN-4La-3@gated-at.bofh.it> |
| In reply to | #166766 |
On Sat 16 Apr 2016 at 15:08:58 (+0200), tomas@tuxteam.de wrote:
> On Sat, Apr 16, 2016 at 01:22:09PM +0100, Aero Maxx wrote:
> > 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.
>
> > 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.
>
> The [[ is correct bash syntax. To try to pinpoint the problem, try
> running the script with "bash <script>". If you don't want to run
> the script but just to check syntax, you might want to try
> "bash -n <script>".
>
> If that works out OK, perhaps your script is still being invoked
> under dash?
Yes, I would expect "line 8:" from bash, not just "8:", and one
filename, not two. OTOH dash does print two filenames.
Also
$ man bash | grep '\[\[' | wc
14 183 1318
$ man dash | grep '\[\[' | wc
0 0 0
$ man bash | grep '==' | wc
6 83 498
$ man dash | grep '==' | wc
0 0 0
$
Cheers,
David.
[toc] | [prev] | [next] | [standalone]
| From | "Thomas Schmitt" <scdbackup@gmx.net> |
|---|---|
| Date | 2016-04-16 16:30 +0200 |
| Message-ID | <rozov-4QQ-31@gated-at.bofh.it> |
| In reply to | #166766 |
Hi, Aero Maxx wrote: > >wordpress_beta.sh: 8: bashtest.sh: [[: not found If it is called "bashtest.sh" then it is plausible that it wants to be run by bash. Obviously it expects /bin/sh to be bash. tomas@tuxteam.de wrote: > try running the script with "bash <script>". [...] > If that works out OK, perhaps your script is still being invoked > under dash? Or perhaps its parent invokes it by /bin/sh on its own ? I wonder whether bash is guaranteed to offer all features of dash. In that case one could revert the migration of /bin/sh to dash and hope that all dash scripts continue to work. If compatibility with Fedora is an essential goal, it might be worth to risk potential dash expectation problems. On my system i see the link /bin/sh -> dash For a quick test i'd do: rm /bin/sh ln -s bash /bin/sh On https://wiki.ubuntu.com/DashAsBinSh i see this advise: sudo dpkg-reconfigure dash (But i fail to see this purpose promised in man dpkg-reconfigure.) Have a nice day :) Thomas
[toc] | [prev] | [next] | [standalone]
| From | Aero Maxx <aero.maxx.d@gmail.com> |
|---|---|
| Date | 2016-04-16 16:50 +0200 |
| Message-ID | <rozHQ-50s-17@gated-at.bofh.it> |
| In reply to | #166766 |
On 16/04/2016 14:08, tomas@tuxteam.de wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On Sat, Apr 16, 2016 at 01:22:09PM +0100, Aero Maxx wrote: >> 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. >> 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. > The [[ is correct bash syntax. To try to pinpoint the problem, try > running the script with "bash <script>". If you don't want to run > the script but just to check syntax, you might want to try > "bash -n <script>". > > If that works out OK, perhaps your script is still being invoked > under dash? I tried that it works thank you, I mistaken assumed that because I changed the shebang line to be bash instead of sh, and then ran it using "sh <script>" it would work, but obviously I got the same errors as before, and I wasn't aware that there was one called bash also, but now I think of it that's quite obvious. Anyway thank you to everyone that responded to my message! --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus
[toc] | [prev] | [next] | [standalone]
| From | Gene Heskett <gheskett@shentel.net> |
|---|---|
| Date | 2016-04-16 17:40 +0200 |
| Message-ID | <roAud-5LI-1@gated-at.bofh.it> |
| In reply to | #166773 |
On Saturday 16 April 2016 10:47:24 Aero Maxx wrote: > On 16/04/2016 14:08, tomas@tuxteam.de wrote: > > -----BEGIN PGP SIGNED MESSAGE----- > > Hash: SHA1 > > > > On Sat, Apr 16, 2016 at 01:22:09PM +0100, Aero Maxx wrote: > >> 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. > >> 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. > > > > The [[ is correct bash syntax. To try to pinpoint the problem, try > > running the script with "bash <script>". If you don't want to run > > the script but just to check syntax, you might want to try > > "bash -n <script>". > > > > If that works out OK, perhaps your script is still being invoked > > under dash? > > I tried that it works thank you, I mistaken assumed that because I > changed the shebang line to be bash instead of sh, > and then ran it using "sh <script>" it would work, but obviously I got > the same errors as before, and I wasn't aware that > there was one called bash also, but now I think of it that's quite > obvious. > > Anyway thank you to everyone that responded to my message! > FWIW, bash I believe, is the grey haired old man in the shell arena, I was using it way back in my amiga days as someone had apparently ported it to amigados 2 decades and change ago. We also had ksh and csh, but they didn't have the power of bash or ARexx. And I still miss ARexx. Even bash cannot do the intimate to the os things that ARexx could do. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page <http://geneslinuxbox.net:6309/gene>
[toc] | [prev] | [next] | [standalone]
| From | Jeremy Nicoll <jn.ml.dbn.25@letterboxes.org> |
|---|---|
| Date | 2016-04-16 22:40 +0200 |
| Message-ID | <roFax-WA-3@gated-at.bofh.it> |
| In reply to | #166775 |
On Sat, 16 Apr 2016, at 16:33, Gene Heskett wrote: > And I still miss ARexx. > Even bash cannot do the intimate to the os things that ARexx could do. Have you considered using Regina REXX or ooREXX instead? -- Jeremy Nicoll - my opinions are my own.
[toc] | [prev] | [next] | [standalone]
| From | Gene Heskett <gheskett@shentel.net> |
|---|---|
| Date | 2016-04-17 01:20 +0200 |
| Message-ID | <roHFo-2TJ-13@gated-at.bofh.it> |
| In reply to | #166793 |
On Saturday 16 April 2016 16:30:19 Jeremy Nicoll wrote: > On Sat, 16 Apr 2016, at 16:33, Gene Heskett wrote: > > And I still miss ARexx. > > Even bash cannot do the intimate to the os things that ARexx could > > do. > > Have you considered using Regina REXX or ooREXX instead? Yes, but typically both have bailed out, syntax error because the syscall they tried to do is not part of their version of the language. Usually by line 3 of the script. ARexx it turns out, is a HUGE superset of Regina Rexx. And ooRexx had dependencies that were not available in the repos at the time. So I do about 1/3rd of what ARexx could do, in half the bash code now. Thanks Jeremy. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page <http://geneslinuxbox.net:6309/gene>
[toc] | [prev] | [next] | [standalone]
| From | <tomas@tuxteam.de> |
|---|---|
| Date | 2016-04-17 18:00 +0200 |
| Message-ID | <roXh9-6HZ-23@gated-at.bofh.it> |
| In reply to | #166773 |
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sat, Apr 16, 2016 at 03:47:24PM +0100, Aero Maxx wrote: > On 16/04/2016 14:08, tomas@tuxteam.de wrote: > >-----BEGIN PGP SIGNED MESSAGE----- > >Hash: SHA1 > > > >On Sat, Apr 16, 2016 at 01:22:09PM +0100, Aero Maxx wrote: > >>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. > >>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. > >The [[ is correct bash syntax. To try to pinpoint the problem, try > >running the script with "bash <script>". If you don't want to run > >the script but just to check syntax, you might want to try > >"bash -n <script>". > > > >If that works out OK, perhaps your script is still being invoked > >under dash? > > I tried that it works thank you, I mistaken assumed that because I > changed the shebang line to be bash instead of sh, > and then ran it using "sh <script>" it would work, but obviously I > got the same errors as before, and I wasn't aware that > there was one called bash also, but now I think of it that's quite obvious. Ah, now I see. If you call it explicitly as above, you decide which shell is used (which is sh, which is dash by default in Debian [1]). In that case, the shebang line is interpreted as a comment, like every line preceded by a # in all shells. The shebang line unfolds its magic only when you invoke the script directly, that is "<script>" instead of "sh <script>": then the kernel looks at the file to find out what "interpreter" to call. If it's an elf, then it goes to ld.so, if it has a shebang line then it's the program (and possibly arguments) mentioned there. There are more possibilities, depending on the binfmt modules [2] [1] It used to be bash, but dash is much smaller, lighter and faster, so it was decided to use it for all the infrastructure (you get faster boots an can build smaller systems for limited resources). For day-to-day desktop use, bash or zsh are more comfy. [2] <https://en.wikipedia.org/wiki/Binfmt_misc> regards - -- t -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlcTsp8ACgkQBcgs9XrR2kY0XgCdEFMrHWwAbmBWDMnHl9Q0+Xrp gcwAn2OvWzSyYuYFjt8+iNHXbG6vSvcL =b8hN -----END PGP SIGNATURE-----
[toc] | [prev] | [standalone]
Back to top | Article view | linux.debian.user
csiph-web