Skip to main content
Feb 11, 2018 3:22 PM UTC

Bash arrays not working properly?

Here’s a little script, call it mygit, that works for me on Ubuntu Linux:

#!/usr/bin/bash
git ${@}

> mygit commit -m "Two words."
[commit works; commit message is "Two words."]

It doesn’t work on z/OS, though:

#!/rsusr/ported/bin/bash
git ${@}

> mygit commit -m "Two words."
error: pathspec 'words.' did not match any file(s) known to git.

It looks like the array of input parameters is being passed to the git command as individual words, not as a proper array. How do I make this work?

    2 replies

    Tatiana Balaburkina
    Rocketeer
    Feb 12, 2018 8:22 AM UTC

    Here’s a little script, call it mygit, that works for me on Ubuntu Linux:

    #!/usr/bin/bash
    git ${@}
    
    > mygit commit -m "Two words."
    [commit works; commit message is "Two words."]
    

    It doesn’t work on z/OS, though:

    #!/rsusr/ported/bin/bash
    git ${@}
    
    > mygit commit -m "Two words."
    error: pathspec 'words.' did not match any file(s) known to git.
    

    It looks like the array of input parameters is being passed to the git command as individual words, not as a proper array. How do I make this work?

    Hi Tony,

    I have no idea, why it works on Ubuntu. Cause it doesn’t work on CentOS. And it is normal bash behavior:
    Link1
    Link2

    Use this script:

    #!/rsusr/ported/bin/bash
    git "${@}"
    

    Thanks,
    Tatyana

    Feb 12, 2018 1:18 PM UTC

    Hi Tony,

    I have no idea, why it works on Ubuntu. Cause it doesn’t work on CentOS. And it is normal bash behavior:
    Link1
    Link2

    Use this script:

    #!/rsusr/ported/bin/bash
    git "${@}"
    

    Thanks,
    Tatyana

    Of course. How intuitive.

    Thanks, Tatyana.