【发布时间】:2017-08-14 16:23:03
【问题描述】:
这是别名:
# make a tmux session in working dir with the name of the dir
alias th='tmux new -s $(pwd | tr '\/' '\n' | tail -n 1)'
由于转义字符或别名中的' 单引号,它不起作用。打印出来
$ type --all th
th is aliased to `tmux new -s $(pwd | tr / n | tail -n 1)'
看起来它只是去掉了'和\。
我最终通过将单引号更改为双引号来修复它。
# make a tmux session in working dir with the name of the dir
alias th='tmux new -s $(pwd | tr "\/" "\n" | tail -n 1)'
我的问题是之前的工作是如何工作的?不应该 bash 抛出解析错误。
【问题讨论】:
-
并没有真正回答您的问题,但由于您标记了 bash,我会将
$(pwd | ...)换成"${PWD##*/}"。 -
顺便说一句,虽然 通常
echo是一个非常糟糕的调试工具选择(有几种方法可以修改它打算按原样显示的数据),它实际上就足够了在这里显示问题:您会看到echo 'tmux new -s $(pwd | tr '\/' '\n' | tail -n 1)'没有显示任何内部引号,因为 - 这些引号是句法而不是文字 - 它们在解析过程中被消耗。
标签: linux bash unix .bash-profile aliases