首页 > 解决方案 > 别名有效,但无法手动运行命令

问题描述

alias git-repo="xdg-open '$(git config --get remote.origin.url | sed -e 's/:/\//g' -e 's/ssh\/\/\///g' -e 's/git@/https:\/\//g')'"

这个别名有效,但是当我尝试手动运行它时它不会:

xdg-open '$(git config --get remote.origin.url | sed -e 's/:/\//g' -e 's/ssh\/\/\///g' -e 's/git@/https:\/\//g')'

我究竟做错了什么?

标签: bashshellalias

解决方案


不应在引号中使用变量表达式。试试这个:

xdg-open $(git config --get remote.origin.url | sed -e "s/:/\//g" -e "s/ssh\/\/\///g" -e "s/git@/https:\/\//g")

推荐阅读