I can't use bash 5 syntax even after configuring it in MacOSX

前端 未结 3 770
南笙
南笙 2021-01-25 19:54

I am relatively new to bash.

I had bash 3 In my mac by default.

GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18)
Copyright (C) 2007 Free Softw         


        
相关标签:
3条回答
  • 2021-01-25 20:12

    homebrew installs programs into /usr/local/bin so if you want to use the version installed by homebrew you need to either run:

    /usr/local/bin/bash --version
    

    or ensure that /usr/local/bin occurs before /bin on your PATH, e.g.

    export PATH=/usr/local/bin:PATH
    
    0 讨论(0)
  • 2021-01-25 20:16

    If you have two versions of bash installed, you need to make sure you are running the right one. In a script you need a first line like:

    #!/usr/local/bin/bash
    

    (Adjust path as necessary for your installation.)

    If you are interactive, make sure you are actually running the version of bash you expect, not just that it's the first 'bash' in your search path.

    0 讨论(0)
  • 2021-01-25 20:23

    The bash -version (or bash --version) command tells you the version of Bash that you would get if you ran bash.

    But I'm guessing that you're not manually running bash; rather, you're just opening the shell, which is probably still the older version of Bash. (It's quite possible, and not even that unusual, to have two copies of Bash installed on a system in different locations.) To check this, you can run echo "$BASH_VERSION" to see the version of Bash that you're actual typing in.

    To fix this, you will need to configure your machine to use the newer version of Bash as your shell. (Or you can just run bash manually.)

    0 讨论(0)
提交回复
热议问题