Bash脚本,返回awk:无法打开文件〜/.ssh/config [英] Bash script, returns awk: can't open file ~/.ssh/config
本文介绍了Bash脚本,返回awk:无法打开文件〜/.ssh/config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以直接在命令行中唤醒该文件,但是当我尝试从脚本中使用它时,它就会中断.不知道为什么.这是我的剧本
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
推荐答案
在bash中引号不会扩展〜
.我建议使用 $ HOME
:
In quotes bash does not expand ~
. I suggest to use $HOME
:
ssh_config_path="$HOME/.ssh/config"
这篇关于Bash脚本,返回awk:无法打开文件〜/.ssh/config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文