Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm looking to switch from bash to zsh but concerned about compatibility of bash scripts.

Are all bash scripts/functions compatible with zsh? Therefore, if that is true is zsh just an enhancement to bash?

share|improve this question
    
I found this useful: askubuntu.com/questions/1577/moving-from-bash-to-zsh –  chrisjlee May 9 '12 at 14:03

3 Answers 3

up vote 16 down vote accepted

If your scripts start with the line #!/bin/bash they will still be run using bash, even if your default shell is zsh.

I've found the syntax of zsh really close to the one of bash, and I did not pay attention if there was really some incompatibilities. I switched 6 yeras ago from bash to zsh seemlessly.

share|improve this answer
    
What was your most challenging part of switching over? –  chrisjlee May 8 '12 at 20:36
1  
None. My personal scripts add the proper reference to bash and I had found a good .zshrc to start with. Zsh and bash were enough similar that I did not really find it challenging. –  Huygens May 8 '12 at 20:39

Zsh can run most Bourne, POSIX or ksh88 scripts if you put it in the right emulation mode (emulate sh or emulate ksh). It doesn't support all features of bash or ksh93. Zsh has most features of bash, but in many cases with a different syntax.

The shell you use interactively is irrelevant for any script you have. The shell that runs the scripts is the one indicated in the first line, the shebang line. For example, if the script starts with #!/bin/bash, it will be executed by bash.

If you've customized bash, you won't be able just rename your .bashrc to .zshrc. Some things can be shared, for example aliases and functions, as long as you stick to the intersection between the two shells (the intersection is close to ksh88 and pdksh). Other things, such as prompt settings, completion functions and most options, will need to be completely rewritten.

share|improve this answer
    
And what about bashrc ? –  warl0ck May 9 '12 at 4:26

But sometimes, there is incompability and may cause danger(This made me confused last night). So just ensure you have "#!/usr/bin/env bash" at the first line.

This passage will help a lot. http://slopjong.de/2012/07/02/compatibility-between-zsh-and-bash/

share|improve this answer
2  
Welcome to Unix & Linux! Generally we like answers on the site to be able to stand on their own - Links are great, but if that link ever breaks the answer should have enough information to still be helpful. Please consider editing your answer to include more detail. See the FAQ for more info. –  slm Apr 6 '13 at 1:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.