【问题标题】:Bash script, returns awk: can't open file ~/.ssh/configBash 脚本,返回 awk: can't open file ~/.ssh/config
【发布时间】:2016-11-18 20:46:17
【问题描述】:

我可以直接从命令行 awk 这个文件,但是当我尝试从我的脚本中使用它时它会中断。不知道为什么。这是我的脚本

#!/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

【问题讨论】:

  • 你在哪里使用读取命令中的$username
  • 还没用过

标签: bash unix ssh tilde-expansion


【解决方案1】:

引号中的 bash 不会扩展 ~。我建议使用$HOME:

ssh_config_path="$HOME/.ssh/config"

【讨论】:

  • 或者省略引号。
猜你喜欢
  • 2019-12-15
  • 2017-02-08
  • 2015-01-21
  • 2013-01-30
  • 2018-04-20
  • 1970-01-01
  • 1970-01-01
  • 2019-08-13
  • 2013-08-17
相关资源
最近更新 更多