问题
I'm able to awk this file directly from the command line but when I try to use it from my script it breaks. Not sure why. Heres my script
#!/bin/bash
ssh_config_path="~/.ssh/config"
echo -n "Enter the username of the account you'd like to switch to > "
read username
awk '
!x{x=sub(/github-secondary/,"github.com")}
!y{y=sub(/github\.com/,"github-secondary")}
1' $ssh_config_path
回答1:
In quotes bash does not expand ~
. I suggest to use $HOME
:
ssh_config_path="$HOME/.ssh/config"
来源:https://stackoverflow.com/questions/40685676/bash-script-returns-awk-cant-open-file-ssh-config