Switching to `zsh`: Are all bash scripts compatible with `zsh`?












45















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
















45















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














45












45








45


8






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'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?







bash zsh






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 9 '12 at 0:38







chrisjlee

















asked May 8 '12 at 20:02









chrisjleechrisjlee

2,492123350




2,492123350













  • I found this useful: askubuntu.com/questions/1577/moving-from-bash-to-zsh

    – chrisjlee
    May 9 '12 at 14:03



















  • I found this useful: askubuntu.com/questions/1577/moving-from-bash-to-zsh

    – chrisjlee
    May 9 '12 at 14:03

















I found this useful: askubuntu.com/questions/1577/moving-from-bash-to-zsh

– chrisjlee
May 9 '12 at 14:03





I found this useful: askubuntu.com/questions/1577/moving-from-bash-to-zsh

– chrisjlee
May 9 '12 at 14:03










3 Answers
3






active

oldest

votes


















43














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






  • 3





    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






  • 3





    can you list your .zshrc :)

    – neaumusic
    Jun 3 '16 at 8:44











  • But if the line #!/bin/bash will be ignored if running the script file like source ./script.sh?

    – LCB
    Jun 13 '18 at 10:58











  • @LCB I guess so. But I usually run my scripts without invoking source. I only source “scripts” which are more configuration file (e.g. export, alias, etc.). Those need some adaptations if they contain functions or bashism. Btw, I’m using now fish instead of zsh.

    – Huygens
    Jun 13 '18 at 14:23



















23














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.



If you're writing a snippet for people to source from their .bashrc or .zshrc and you don't want to maintain two versions, stick to a common subset of bash and zsh features, which includes most of bash's programming features. Put your whole code in functions, and put the following line at the top of each function:



if [ -n "$ZSH_VERSION" ]; then emulate -L ksh; fi


You can use emulate sh instead of emulate ksh to be closer to plain sh syntax, which is what you need for .profile.



If a function calls another function, the other function inherits the emulate setting, so you don't need to put this line in internal functions, only in functions called by the end-user.






share|improve this answer


























  • The shell you use is irrelevant if you run your scripts as ./my_script.sh. source my_script.sh and . my_script.sh will run it is as the current shell, ignoring any shebang.

    – BallpointBen
    Aug 29 '18 at 15:03



















0














If the shebang is #!/bin/bash and you start the script as ./script the script will be executed by bash. Absolutely no problem here.



However, if you execute zsh ./script or source it . ./script to the running zsh instance, it is quite common that the syntax of bash and zsh won't match.



For example, zsh doesn't split parameter expansions by default, bash has a help builtin, there is no read -p prompt in zsh (the syntax is very different read cmd?prompt, arrays start on 1 (not 0) in zsh,commandonly search for external commands in zsh, or there is no (simple) equivalent to${foo^}` (uppercase only first character) in zsh, among others. This is a long list of (mostly) similarities and some differences.



In some cases, zsh may be told to emulate other shells. In some cases, there is no common syntax portable to both shells possible (without using aliases or functions to emulate portable solutions).



However, zsh has many (a lot) of extensions that make easier to work interactively. That is at the same time an excellent reason to switch and a problem:





  1. Pro zsh




    • It is very nice to be able to see command syntax options pressing a tab.

    • Another major benefit of zsh is error correction when you make a typo. Rather than just display error: command not found, zsh will try to interpret what you tried to type. zsh will accept this input as a valid command.

    • Also, zsh has many modifiers to expansions that allow a large range of solutions. Like: list only files: ls *(.) (which is difficult with other shells). Even if when looking deeply enough the answer becomes also complex in zsh (print -rl -- *(/)).

    • Accept math with floats (with some caveats).




  2. Con zsh:




    • Bash is the default shell in many more systems.

    • Many zsh options doesn't help directly to writing bash compatible scripts.

    • It even could become a big problem trying to learn two shells at the same time.




In the end, it is your choice, and, I always like more choices.






share|improve this answer

























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f38172%2fswitching-to-zsh-are-all-bash-scripts-compatible-with-zsh%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    43














    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






    • 3





      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






    • 3





      can you list your .zshrc :)

      – neaumusic
      Jun 3 '16 at 8:44











    • But if the line #!/bin/bash will be ignored if running the script file like source ./script.sh?

      – LCB
      Jun 13 '18 at 10:58











    • @LCB I guess so. But I usually run my scripts without invoking source. I only source “scripts” which are more configuration file (e.g. export, alias, etc.). Those need some adaptations if they contain functions or bashism. Btw, I’m using now fish instead of zsh.

      – Huygens
      Jun 13 '18 at 14:23
















    43














    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






    • 3





      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






    • 3





      can you list your .zshrc :)

      – neaumusic
      Jun 3 '16 at 8:44











    • But if the line #!/bin/bash will be ignored if running the script file like source ./script.sh?

      – LCB
      Jun 13 '18 at 10:58











    • @LCB I guess so. But I usually run my scripts without invoking source. I only source “scripts” which are more configuration file (e.g. export, alias, etc.). Those need some adaptations if they contain functions or bashism. Btw, I’m using now fish instead of zsh.

      – Huygens
      Jun 13 '18 at 14:23














    43












    43








    43







    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













    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












    share|improve this answer



    share|improve this answer










    answered May 8 '12 at 20:35









    HuygensHuygens

    4,97822231




    4,97822231













    • What was your most challenging part of switching over?

      – chrisjlee
      May 8 '12 at 20:36






    • 3





      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






    • 3





      can you list your .zshrc :)

      – neaumusic
      Jun 3 '16 at 8:44











    • But if the line #!/bin/bash will be ignored if running the script file like source ./script.sh?

      – LCB
      Jun 13 '18 at 10:58











    • @LCB I guess so. But I usually run my scripts without invoking source. I only source “scripts” which are more configuration file (e.g. export, alias, etc.). Those need some adaptations if they contain functions or bashism. Btw, I’m using now fish instead of zsh.

      – Huygens
      Jun 13 '18 at 14:23



















    • What was your most challenging part of switching over?

      – chrisjlee
      May 8 '12 at 20:36






    • 3





      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






    • 3





      can you list your .zshrc :)

      – neaumusic
      Jun 3 '16 at 8:44











    • But if the line #!/bin/bash will be ignored if running the script file like source ./script.sh?

      – LCB
      Jun 13 '18 at 10:58











    • @LCB I guess so. But I usually run my scripts without invoking source. I only source “scripts” which are more configuration file (e.g. export, alias, etc.). Those need some adaptations if they contain functions or bashism. Btw, I’m using now fish instead of zsh.

      – Huygens
      Jun 13 '18 at 14:23

















    What was your most challenging part of switching over?

    – chrisjlee
    May 8 '12 at 20:36





    What was your most challenging part of switching over?

    – chrisjlee
    May 8 '12 at 20:36




    3




    3





    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





    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




    3




    3





    can you list your .zshrc :)

    – neaumusic
    Jun 3 '16 at 8:44





    can you list your .zshrc :)

    – neaumusic
    Jun 3 '16 at 8:44













    But if the line #!/bin/bash will be ignored if running the script file like source ./script.sh?

    – LCB
    Jun 13 '18 at 10:58





    But if the line #!/bin/bash will be ignored if running the script file like source ./script.sh?

    – LCB
    Jun 13 '18 at 10:58













    @LCB I guess so. But I usually run my scripts without invoking source. I only source “scripts” which are more configuration file (e.g. export, alias, etc.). Those need some adaptations if they contain functions or bashism. Btw, I’m using now fish instead of zsh.

    – Huygens
    Jun 13 '18 at 14:23





    @LCB I guess so. But I usually run my scripts without invoking source. I only source “scripts” which are more configuration file (e.g. export, alias, etc.). Those need some adaptations if they contain functions or bashism. Btw, I’m using now fish instead of zsh.

    – Huygens
    Jun 13 '18 at 14:23













    23














    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.



    If you're writing a snippet for people to source from their .bashrc or .zshrc and you don't want to maintain two versions, stick to a common subset of bash and zsh features, which includes most of bash's programming features. Put your whole code in functions, and put the following line at the top of each function:



    if [ -n "$ZSH_VERSION" ]; then emulate -L ksh; fi


    You can use emulate sh instead of emulate ksh to be closer to plain sh syntax, which is what you need for .profile.



    If a function calls another function, the other function inherits the emulate setting, so you don't need to put this line in internal functions, only in functions called by the end-user.






    share|improve this answer


























    • The shell you use is irrelevant if you run your scripts as ./my_script.sh. source my_script.sh and . my_script.sh will run it is as the current shell, ignoring any shebang.

      – BallpointBen
      Aug 29 '18 at 15:03
















    23














    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.



    If you're writing a snippet for people to source from their .bashrc or .zshrc and you don't want to maintain two versions, stick to a common subset of bash and zsh features, which includes most of bash's programming features. Put your whole code in functions, and put the following line at the top of each function:



    if [ -n "$ZSH_VERSION" ]; then emulate -L ksh; fi


    You can use emulate sh instead of emulate ksh to be closer to plain sh syntax, which is what you need for .profile.



    If a function calls another function, the other function inherits the emulate setting, so you don't need to put this line in internal functions, only in functions called by the end-user.






    share|improve this answer


























    • The shell you use is irrelevant if you run your scripts as ./my_script.sh. source my_script.sh and . my_script.sh will run it is as the current shell, ignoring any shebang.

      – BallpointBen
      Aug 29 '18 at 15:03














    23












    23








    23







    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.



    If you're writing a snippet for people to source from their .bashrc or .zshrc and you don't want to maintain two versions, stick to a common subset of bash and zsh features, which includes most of bash's programming features. Put your whole code in functions, and put the following line at the top of each function:



    if [ -n "$ZSH_VERSION" ]; then emulate -L ksh; fi


    You can use emulate sh instead of emulate ksh to be closer to plain sh syntax, which is what you need for .profile.



    If a function calls another function, the other function inherits the emulate setting, so you don't need to put this line in internal functions, only in functions called by the end-user.






    share|improve this answer















    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.



    If you're writing a snippet for people to source from their .bashrc or .zshrc and you don't want to maintain two versions, stick to a common subset of bash and zsh features, which includes most of bash's programming features. Put your whole code in functions, and put the following line at the top of each function:



    if [ -n "$ZSH_VERSION" ]; then emulate -L ksh; fi


    You can use emulate sh instead of emulate ksh to be closer to plain sh syntax, which is what you need for .profile.



    If a function calls another function, the other function inherits the emulate setting, so you don't need to put this line in internal functions, only in functions called by the end-user.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Aug 8 '18 at 20:50

























    answered May 8 '12 at 23:04









    GillesGilles

    535k12810811599




    535k12810811599













    • The shell you use is irrelevant if you run your scripts as ./my_script.sh. source my_script.sh and . my_script.sh will run it is as the current shell, ignoring any shebang.

      – BallpointBen
      Aug 29 '18 at 15:03



















    • The shell you use is irrelevant if you run your scripts as ./my_script.sh. source my_script.sh and . my_script.sh will run it is as the current shell, ignoring any shebang.

      – BallpointBen
      Aug 29 '18 at 15:03

















    The shell you use is irrelevant if you run your scripts as ./my_script.sh. source my_script.sh and . my_script.sh will run it is as the current shell, ignoring any shebang.

    – BallpointBen
    Aug 29 '18 at 15:03





    The shell you use is irrelevant if you run your scripts as ./my_script.sh. source my_script.sh and . my_script.sh will run it is as the current shell, ignoring any shebang.

    – BallpointBen
    Aug 29 '18 at 15:03











    0














    If the shebang is #!/bin/bash and you start the script as ./script the script will be executed by bash. Absolutely no problem here.



    However, if you execute zsh ./script or source it . ./script to the running zsh instance, it is quite common that the syntax of bash and zsh won't match.



    For example, zsh doesn't split parameter expansions by default, bash has a help builtin, there is no read -p prompt in zsh (the syntax is very different read cmd?prompt, arrays start on 1 (not 0) in zsh,commandonly search for external commands in zsh, or there is no (simple) equivalent to${foo^}` (uppercase only first character) in zsh, among others. This is a long list of (mostly) similarities and some differences.



    In some cases, zsh may be told to emulate other shells. In some cases, there is no common syntax portable to both shells possible (without using aliases or functions to emulate portable solutions).



    However, zsh has many (a lot) of extensions that make easier to work interactively. That is at the same time an excellent reason to switch and a problem:





    1. Pro zsh




      • It is very nice to be able to see command syntax options pressing a tab.

      • Another major benefit of zsh is error correction when you make a typo. Rather than just display error: command not found, zsh will try to interpret what you tried to type. zsh will accept this input as a valid command.

      • Also, zsh has many modifiers to expansions that allow a large range of solutions. Like: list only files: ls *(.) (which is difficult with other shells). Even if when looking deeply enough the answer becomes also complex in zsh (print -rl -- *(/)).

      • Accept math with floats (with some caveats).




    2. Con zsh:




      • Bash is the default shell in many more systems.

      • Many zsh options doesn't help directly to writing bash compatible scripts.

      • It even could become a big problem trying to learn two shells at the same time.




    In the end, it is your choice, and, I always like more choices.






    share|improve this answer






























      0














      If the shebang is #!/bin/bash and you start the script as ./script the script will be executed by bash. Absolutely no problem here.



      However, if you execute zsh ./script or source it . ./script to the running zsh instance, it is quite common that the syntax of bash and zsh won't match.



      For example, zsh doesn't split parameter expansions by default, bash has a help builtin, there is no read -p prompt in zsh (the syntax is very different read cmd?prompt, arrays start on 1 (not 0) in zsh,commandonly search for external commands in zsh, or there is no (simple) equivalent to${foo^}` (uppercase only first character) in zsh, among others. This is a long list of (mostly) similarities and some differences.



      In some cases, zsh may be told to emulate other shells. In some cases, there is no common syntax portable to both shells possible (without using aliases or functions to emulate portable solutions).



      However, zsh has many (a lot) of extensions that make easier to work interactively. That is at the same time an excellent reason to switch and a problem:





      1. Pro zsh




        • It is very nice to be able to see command syntax options pressing a tab.

        • Another major benefit of zsh is error correction when you make a typo. Rather than just display error: command not found, zsh will try to interpret what you tried to type. zsh will accept this input as a valid command.

        • Also, zsh has many modifiers to expansions that allow a large range of solutions. Like: list only files: ls *(.) (which is difficult with other shells). Even if when looking deeply enough the answer becomes also complex in zsh (print -rl -- *(/)).

        • Accept math with floats (with some caveats).




      2. Con zsh:




        • Bash is the default shell in many more systems.

        • Many zsh options doesn't help directly to writing bash compatible scripts.

        • It even could become a big problem trying to learn two shells at the same time.




      In the end, it is your choice, and, I always like more choices.






      share|improve this answer




























        0












        0








        0







        If the shebang is #!/bin/bash and you start the script as ./script the script will be executed by bash. Absolutely no problem here.



        However, if you execute zsh ./script or source it . ./script to the running zsh instance, it is quite common that the syntax of bash and zsh won't match.



        For example, zsh doesn't split parameter expansions by default, bash has a help builtin, there is no read -p prompt in zsh (the syntax is very different read cmd?prompt, arrays start on 1 (not 0) in zsh,commandonly search for external commands in zsh, or there is no (simple) equivalent to${foo^}` (uppercase only first character) in zsh, among others. This is a long list of (mostly) similarities and some differences.



        In some cases, zsh may be told to emulate other shells. In some cases, there is no common syntax portable to both shells possible (without using aliases or functions to emulate portable solutions).



        However, zsh has many (a lot) of extensions that make easier to work interactively. That is at the same time an excellent reason to switch and a problem:





        1. Pro zsh




          • It is very nice to be able to see command syntax options pressing a tab.

          • Another major benefit of zsh is error correction when you make a typo. Rather than just display error: command not found, zsh will try to interpret what you tried to type. zsh will accept this input as a valid command.

          • Also, zsh has many modifiers to expansions that allow a large range of solutions. Like: list only files: ls *(.) (which is difficult with other shells). Even if when looking deeply enough the answer becomes also complex in zsh (print -rl -- *(/)).

          • Accept math with floats (with some caveats).




        2. Con zsh:




          • Bash is the default shell in many more systems.

          • Many zsh options doesn't help directly to writing bash compatible scripts.

          • It even could become a big problem trying to learn two shells at the same time.




        In the end, it is your choice, and, I always like more choices.






        share|improve this answer















        If the shebang is #!/bin/bash and you start the script as ./script the script will be executed by bash. Absolutely no problem here.



        However, if you execute zsh ./script or source it . ./script to the running zsh instance, it is quite common that the syntax of bash and zsh won't match.



        For example, zsh doesn't split parameter expansions by default, bash has a help builtin, there is no read -p prompt in zsh (the syntax is very different read cmd?prompt, arrays start on 1 (not 0) in zsh,commandonly search for external commands in zsh, or there is no (simple) equivalent to${foo^}` (uppercase only first character) in zsh, among others. This is a long list of (mostly) similarities and some differences.



        In some cases, zsh may be told to emulate other shells. In some cases, there is no common syntax portable to both shells possible (without using aliases or functions to emulate portable solutions).



        However, zsh has many (a lot) of extensions that make easier to work interactively. That is at the same time an excellent reason to switch and a problem:





        1. Pro zsh




          • It is very nice to be able to see command syntax options pressing a tab.

          • Another major benefit of zsh is error correction when you make a typo. Rather than just display error: command not found, zsh will try to interpret what you tried to type. zsh will accept this input as a valid command.

          • Also, zsh has many modifiers to expansions that allow a large range of solutions. Like: list only files: ls *(.) (which is difficult with other shells). Even if when looking deeply enough the answer becomes also complex in zsh (print -rl -- *(/)).

          • Accept math with floats (with some caveats).




        2. Con zsh:




          • Bash is the default shell in many more systems.

          • Many zsh options doesn't help directly to writing bash compatible scripts.

          • It even could become a big problem trying to learn two shells at the same time.




        In the end, it is your choice, and, I always like more choices.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 27 at 5:06

























        answered Jan 27 at 3:46









        IsaacIsaac

        11.8k11752




        11.8k11752






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f38172%2fswitching-to-zsh-are-all-bash-scripts-compatible-with-zsh%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to make a Squid Proxy server?

            Is this a new Fibonacci Identity?

            19世紀