I just switched from Ubuntu to macOS (due to work reasons). And I wanted to transfer my bash aliases to zsh, but they are not working completely.
alias HPC1='ssh -l [username] [server1]'
alias HPC2='ssh -l [username] [server2]'
HPC[0]="HPC1"
HPC[1]="HPC2"
alias HPC='eval "${HPC[$RANDOM % 2]}"'
HPC1
connects to server1 and HPC2
connects to server2. HPC should connect to either server1 or server2 randomly. It works within bash. In macOS (zsh) only the aliases HPC1
and HPC2
work, but not HPC
. Is the syntax different there?
Thanks for helping me out :).
HPC[0]="HPC1"
should result in the error message assignment to invalid subscript range. If you don't get this error message, it means that the code either is not executed by zsh, or maybe by a zsh which is configured to run in Korn-shell compatible mode. – user1934428 Jul 18 '22 at 09:57HPC1
andHPC2
work exactly means. With a invalid subscript range error, it should be clear what the error is. I wonder what exactly doesn't work, in that script, for the OP. – apaderno Jul 18 '22 at 11:18