You are not logged in.

#1 2008-07-04 12:22:17

william7
Member
Registered: 2008-06-18
Posts: 32

changing bash to zsh

I have question, is possible to run .sh scripts under zsh shell?

Offline

#2 2008-07-04 12:24:05

Shaika-Dzari
Member
From: Québec, Canada
Registered: 2006-04-14
Posts: 436
Website

Re: changing bash to zsh

Yes, no problem. smile

Offline

#3 2008-07-04 13:11:24

william7
Member
Registered: 2008-06-18
Posts: 32

Re: changing bash to zsh

ok, but is necessary to edit this script?

changing #! bash header or something like that...?

Last edited by william7 (2008-07-04 13:12:52)

Offline

#4 2008-07-04 13:39:26

shining
Pacman Developer
Registered: 2006-05-10
Posts: 2,043

Re: changing bash to zsh

william7 wrote:

ok, but is necessary to edit this script?

changing #! bash header or something like that...?

This #! bash header is the reason why there is no difference between using bash or zsh when executing the script.
Both shells will spawn a bash process for executing the script.
Now if you change that line, you may (or not) get compatibility problems.

http://en.wikipedia.org/wiki/Shebang_(Unix)


pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))

Offline

#5 2008-07-04 14:50:03

buttons
Member
From: NJ, USA
Registered: 2007-08-04
Posts: 620

Re: changing bash to zsh

shining wrote:

Both shells will spawn a bash process for executing the script.

Um?  If you change the header to #!/bin/zsh, then zsh will run the script, not bash.

If the header is #!/bin/sh, your current shell will decide how to run it.  If your current shell is zsh, it will be run by zsh in a POSIX-compatible way.

If the header is #!/bin/bash, then bash will be spawned to run it.

Last edited by buttons (2008-07-04 14:50:46)


Cthulhu For President!

Offline

#6 2008-07-04 15:22:43

Misfit138
Misfit Emeritus
From: USA
Registered: 2006-11-27
Posts: 4,189

Re: changing bash to zsh

buttons wrote:
shining wrote:

Both shells will spawn a bash process for executing the script.

Um?  If you change the header to #!/bin/zsh, then zsh will run the script, not bash.

If the header is #!/bin/sh, your current shell will decide how to run it.  If your current shell is zsh, it will be run by zsh in a POSIX-compatible way.

If the header is #!/bin/bash, then bash will be spawned to run it.

I thought #!/bin/sh emulated the old Bourne shell...?

Offline

#7 2008-07-04 16:10:42

buttons
Member
From: NJ, USA
Registered: 2007-08-04
Posts: 620

Re: changing bash to zsh

You're right.  See here for compatibility and differences between it and zsh emulation --> http://zsh.dotsrc.org/FAQ/zshfaq02.html


Cthulhu For President!

Offline

#8 2008-07-04 17:48:10

william7
Member
Registered: 2008-06-18
Posts: 32

Re: changing bash to zsh

so...

if script is /bin/bash  zsh starts bash
but is /bin/sh spcript will be start by zsh...

am I right?

Offline

#9 2008-07-04 18:11:24

shining
Pacman Developer
Registered: 2006-05-10
Posts: 2,043

Re: changing bash to zsh

buttons wrote:
shining wrote:

Both shells will spawn a bash process for executing the script.

Um?  If you change the header to #!/bin/zsh, then zsh will run the script, not bash.

Um? Who talked about changing the header? I am talking about a script with /bin/bash header.

If the header is #!/bin/sh, your current shell will decide how to run it.  If your current shell is zsh, it will be run by zsh in a POSIX-compatible way.

If the header is #!/bin/bash, then bash will be spawned to run it.

I don't think this is true either. If the header is /bin/sh, the current shell will spawn /bin/sh. On Arch, by default, /bin/sh is a link to /bin/bash, so bash will be used here.

Also, it is worth mentioning that in this case where bash is invoked as sh, it works in some kind of compatibility mode (closer to POSIX?).
And same with zsh if there was a sh -> zsh symlink.


pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))

Offline

#10 2008-07-04 18:58:04

buttons
Member
From: NJ, USA
Registered: 2007-08-04
Posts: 620

Re: changing bash to zsh

shining wrote:

I don't think this is true either. If the header is /bin/sh, the current shell will spawn /bin/sh. On Arch, by default, /bin/sh is a link to /bin/bash, so bash will be used here.

Also, it is worth mentioning that in this case where bash is invoked as sh, it works in some kind of compatibility mode (closer to POSIX?).
And same with zsh if there was a sh -> zsh symlink.

This is correct, per the link I posted earlier.  Well, dunno about the bash also emulating sh bit.  I think it's true.

When sh is linked to zsh, zsh runs the script in Bourne shell (sh) emulation mode.


Cthulhu For President!

Offline

Board footer

Powered by FluxBB