这是别名:
# 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不应该抛出解析错误吗?
"${PWD##*/}"
来代替$(pwd | ...)
。 - Tom Fenechecho
是一个非常糟糕的调试工具(因为它有几种混淆数据的方式,而这些数据本来是要按原样显示的),但在这里它实际上足以显示问题:你会发现echo 'tmux new -s $(pwd | tr '\/' '\n' | tail -n 1)'
没有显示任何内部引号,因为这些引号是语法上的而不是字面上的,在解析过程中被消耗掉了。 - Charles Duffy