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












44















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
















44















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














44












44








44


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,462123350




2,462123350













  • 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










4 Answers
4






active

oldest

votes


















42














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



















1














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



















  • 6





    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











  • The conditional section on that page is very confused - it omits the crucial &&, as one of the comments points out.

    – RichVel
    Oct 20 '17 at 15:58











  • And now the page is gone, so this answer is completely useless.

    – G-Man
    4 hours ago



















-1














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 it is quite common that the syntax of bash and zsh won't match. For example, zsh doesn't split parameter expansions by default, command only search for external commands, or there is no equivalent to ${foo^} (uppercase unly first character), among others.






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

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    42














    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
















    42














    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














    42












    42








    42







    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,94822231




    4,94822231













    • 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

    533k12810721594




    533k12810721594













    • 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











    1














    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



















    • 6





      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











    • The conditional section on that page is very confused - it omits the crucial &&, as one of the comments points out.

      – RichVel
      Oct 20 '17 at 15:58











    • And now the page is gone, so this answer is completely useless.

      – G-Man
      4 hours ago
















    1














    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



















    • 6





      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











    • The conditional section on that page is very confused - it omits the crucial &&, as one of the comments points out.

      – RichVel
      Oct 20 '17 at 15:58











    • And now the page is gone, so this answer is completely useless.

      – G-Man
      4 hours ago














    1












    1








    1







    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













    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












    share|improve this answer



    share|improve this answer










    answered Apr 6 '13 at 0:53









    凉拌茶叶凉拌茶叶

    111




    111








    • 6





      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











    • The conditional section on that page is very confused - it omits the crucial &&, as one of the comments points out.

      – RichVel
      Oct 20 '17 at 15:58











    • And now the page is gone, so this answer is completely useless.

      – G-Man
      4 hours ago














    • 6





      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











    • The conditional section on that page is very confused - it omits the crucial &&, as one of the comments points out.

      – RichVel
      Oct 20 '17 at 15:58











    • And now the page is gone, so this answer is completely useless.

      – G-Man
      4 hours ago








    6




    6





    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





    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













    The conditional section on that page is very confused - it omits the crucial &&, as one of the comments points out.

    – RichVel
    Oct 20 '17 at 15:58





    The conditional section on that page is very confused - it omits the crucial &&, as one of the comments points out.

    – RichVel
    Oct 20 '17 at 15:58













    And now the page is gone, so this answer is completely useless.

    – G-Man
    4 hours ago





    And now the page is gone, so this answer is completely useless.

    – G-Man
    4 hours ago











    -1














    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 it is quite common that the syntax of bash and zsh won't match. For example, zsh doesn't split parameter expansions by default, command only search for external commands, or there is no equivalent to ${foo^} (uppercase unly first character), among others.






    share|improve this answer






























      -1














      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 it is quite common that the syntax of bash and zsh won't match. For example, zsh doesn't split parameter expansions by default, command only search for external commands, or there is no equivalent to ${foo^} (uppercase unly first character), among others.






      share|improve this answer




























        -1












        -1








        -1







        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 it is quite common that the syntax of bash and zsh won't match. For example, zsh doesn't split parameter expansions by default, command only search for external commands, or there is no equivalent to ${foo^} (uppercase unly first character), among others.






        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 it is quite common that the syntax of bash and zsh won't match. For example, zsh doesn't split parameter expansions by default, command only search for external commands, or there is no equivalent to ${foo^} (uppercase unly first character), among others.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 3 mins ago

























        answered 36 mins ago









        IsaacIsaac

        11.6k11752




        11.6k11752






























            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

            サソリ

            広島県道265号伴広島線

            Accessing regular linux commands in Huawei's Dopra Linux