2

I am exploring the use of WSL 2 for Windows 10, version 2004. My preferred shell is tcsh, which I've installed. I am now trying to set up my usual aliases by placing them in a file such as .tschrc that is read when I start the terminal program under Ubuntu. However, this approach is consistently failing. I have traced this back to problems "source-ing" a file with the "source" command.

For example, suppose .tcshrcSAV2 contains this line:

alias ll 'ls -l'

If I use the source command on this file like so:

source .tcshrcSAV2

I get an error and the alias does not work. The error after executing the source command is:

: Command not found.

The problem is not the source command. It is found and executed. If I do "which source", it is indeed the built-in shell command.

Some sort of alias is created, but it does not work. If I execute the command

ll

I get the following error:

's: invalid option -- '
Try 'ls --help' for more information.

If I list the aliases in my shell, it looks OK:

$> alias
ll      ls -l

However, there is clearly something wrong with the alias. If instead I create the alias at the command line, and not through sourcing the file above, the alias works.

Is this a known problem with tcsh on WSL 2? Thanks!

1 Answer 1

0

Trying on a normal Linux system, it works as usual.

Still on a native Linux system bash shell, typing (without ending the line):

ls -l

and then adding ctrl-v ctrl-m to insert a CR character and validating the line gives OP's error. Editing the file and adding a trailing CR byte so it ends in CRLF - Windows style - instead of LF - Unix/Linux - style gets the same error once sourced in tcsh.

What happens is that ls is asked to use an option with the "letter" CR which isn't a known option. It's displayed back as an additional CR, thus putting back the last ' in place of the l of ls on the same first line of the error displayed.

So I can only deduce that the tool used to edit the file created a line ending in CRLF instead of the expected LF. Perhaps the tool wasn't itself running within WSL. Or perhaps it's related to the terminal interface.

You should probably use vi to create this file (editing it when it's already having CRLFs will still make it tell it kept the [dos] format). So if that's not enough you can still do for example this to remove the trailing CR character:

tr -d '\r' < .tcshrcSAV2 > .tcshrcSAV3
source .tcshrcSAV3
1
  • The origin of this is probably that the content came from a native Windows file originally. I have been using vi to edit it, but there must have been CR in that is invisible and persisted through the vi edit sessions. Aug 30, 2020 at 4:05

You must log in to answer this question.

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