C Shell Environment Variable Error: "Bad: Modifier in $"

C Shell Environment Variable Error: "Bad: Modifier in $"

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

setenv mycomp 

so that when I need to copy files from the remote my.computer.com, 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?

2 Answers

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
/home

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
2

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.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.