c shell 环境变量错误:“错误:$ 中的修饰符”

mar*_*ard 3 environment-variables tcsh

我正在使用 tcsh 并定义一个环境变量,如下所示:

setenv mycomp myusername@my.computer.com
Run Code Online (Sandbox Code Playgroud)

所以当我需要从远程 my.computer.com 复制文件时,我输入以下内容:

scp $mycomp:sourcepath destpath
Run Code Online (Sandbox Code Playgroud)

但是当我这样做时,我收到以下错误:“坏:$ (m) 中的修饰符。” 其中 (m) 是冒号后的第一个字符。

这个错误告诉我什么,我该如何解决?

Mik*_*kel 6

带有冒号的变量扩展将冒号后面的字母视为修饰符。

例如,$dir:h表示$dirh修饰符展开。 h意味着头部,即路径的最后一部分。

% set dir=/home/user
% echo $dir:h
/home
Run Code Online (Sandbox Code Playgroud)

所有信息都在 tcsh(1) 手册页中:

History substitution

   ...

   The word or words in a history reference  can  be  edited,  or  ‘‘modi-
   fied’’,  by following it with one or more modifiers, each preceded by a
   ‘:’:

       h       Remove a trailing pathname component, leaving the head.
       t       Remove all leading pathname components, leaving the tail.
       r       Remove a filename extension ‘.xxx’, leaving the root  name.
       e       Remove all but the extension.
       u       Uppercase the first lowercase letter.
       l       Lowercase the first uppercase letter.
       s/l/r/  Substitute  l  for  r.
       ...


Variable substitution

   ...

   The ‘:’ modifiers described  under  History  substitution,  except  for
   ‘:p’,  can be applied to the substitutions above.
Run Code Online (Sandbox Code Playgroud)

您可以通过将变量名称括在大括号中来避免使用修饰符,例如

scp ${mycomp}:sourcepath destpath
Run Code Online (Sandbox Code Playgroud)