我有一个aliasforyoutube_dl在我的.bashrc文件中添加了一些参数。我想在一个单独的终端中运行它,类似于这里的完成方式。问题是这需要一个字符串作为输入。
我现在的别名:
alias youtube-dl="youtube-dl -ci --restrict-filenames -o '%(title)s.%(ext)s'"
Run Code Online (Sandbox Code Playgroud)
我希望新别名看起来像:
alias youtube-dl='gnome-terminal -e "youtube-dl -ci --restrict-filenames -o '%(title)s.%(ext)s'"'
Run Code Online (Sandbox Code Playgroud)
然而,问题是现在'-strings 被解释为两个单独的字符串。此外,我现在无法将 url 添加为参数。我该如何规避?
你可以搞乱引号和转义,但我更喜欢寻找减少引用级别的方法。例如,您可以gnome-terminal -x改用:
-e, --command=STRING
Execute the argument to this option inside the terminal.
-x, --execute
Execute the remainder of the command line inside the
terminal.
Run Code Online (Sandbox Code Playgroud)
所以,
gnome-terminal -e "youtube-dl -ci --restrict-filenames -o '%(title)s.%(ext)s'"
Run Code Online (Sandbox Code Playgroud)
变成:
gnome-terminal -x youtube-dl -ci --restrict-filenames -o '%(title)s.%(ext)s'
Run Code Online (Sandbox Code Playgroud)
刮掉一层引号。别名将是:
alias youtube-dl='gnome-terminal -x youtube-dl -ci --restrict-filenames -o "%(title)s.%(ext)s"'
Run Code Online (Sandbox Code Playgroud)
或者你可以使用一个函数:
youtube-dl()
{
gnome-terminal -x youtube-dl -ci --restrict-filenames -o '%(title)s.%(ext)s' "$@"
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
755 次 |
| 最近记录: |