Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using tcsh and define an environmental variable as follows:

setenv mycomp

so that when I need to copy files from the remote, I type the following:

scp $mycomp:sourcepath destpath

But when I do this, I get the following error: "Bad : modifier in $ (m)." where (m) is the first character after the colon.

What is this error telling me, and how can I fix it?

share|improve this question
up vote 6 down vote accepted

Variable expansion with a colon after it treats the letters after the colon as modifiers.

For example, $dir:h means expand $dir with the h modifier. h means head, i.e. all but the last part of the path.

% set dir=/home/user
% echo $dir:h

All the info is in the tcsh(1) man page:

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.

You can avoid the modifier by wrapping the variable name in braces, e.g.

scp ${mycomp}:sourcepath destpath
share|improve this answer
Thank you for the explanation, I think that if I want to avoid using {}, then my solution is to switch to the bash shell :). – marshall.ward Jan 17 '11 at 23:23
@Marshall: There are many reasons to prefer Bash over tcsh, but be aware that there are times when you need to use curly braces with variable names in Bash. – Dennis Williamson Jan 17 '11 at 23:47

While I don't have a tcsh environment to test this out I'd guess that when the shell is looking for your environment variable, it is not splitting out on the : and looking for $mycomp:sourcepath as the whole variable name.

I would try aliasing out your scp command.

share|improve this answer
Thanks, ${mycomp}:sourcepath destpath works, so that must be correct. Is using {} the only way to get it to work? – marshall.ward Jan 17 '11 at 23:15
@Marshall: You can use quotes: $"mycomp":sourcepath. – Dennis Williamson Jan 17 '11 at 23:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .