macOS terminal adds whitespace character

On my Mac I tried to redirect stderr to /dev/null like so (assume the file bla does not exist in the current working directory):

cat bla 2>/dev/null

But it just complains that neither bla, nor 2 exists. When I press the up arrow key the command lokks like this (notice the space):

cat bla 2 > /dev/null

I uave tried creating an empty .cshr file and sourcing it to avoid any settings I have made to be the culprit, but it still has this awkward behaviour.

Do you have any idea on what I’m doing wrong?

I’m using zsh which is the default shell. It works as it should apparently.

Darwin cibo 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:29 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T8101 arm64
[email protected] ~ % which zsh          
/bin/zsh
[email protected] ~ % cat bla 2>/dev/null
[email protected] ~ % 

Up arrow also works as it should.

UPDATE: This is a tcsh thing. I’ve had the same results as op by switching to tcsh on MacOS and FreeBSD. Up arrow also bring up the results with an added space.

[cibo:~] ulzeraj% uname -a
Darwin cibo 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:29 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T8101 arm64
[cibo:~] ulzeraj% which tcsh
/bin/tcsh
[cibo:~] ulzeraj% cat bla 2>/dev/null
cat: bla: No such file or directory
cat: 2: No such file or directory
[cibo:~] ulzeraj% 
> uname -a
FreeBSD sanakan.lan.hangar.ninja 13.0-RELEASE-p8 FreeBSD 13.0-RELEASE-p8 #0: Wed Mar 16 14:04:03 CET 2022     [email protected]:/usr/embedded/obj/usr/src/amd64.amd64/sys/GENERIC  amd64
> which tcsh
/bin/tcsh
> echo $SHELL
/bin/tcsh
> cat bla 2>/dev/null
cat: bla: No such file or directory
cat: 2: No such file or directory
> 

@Azulath if you want something more Linux-like change the shell to /bin/bash with the following command:

bash

Make it permanent:

chsh -s /bin/bash
2 Likes

Thanks for looking into this thing and helping me :slight_smile:

Interesting, so this is a bug isn’t it?

What do you mean with more Linux-like? As far as I know, ‘tcsh’ is not a macOS thing. Also, do you or does someone know how to fix this? Or is it - like mentioned above - a bug in tcsh?

Not a bug. CSH (C Shell) and TCSH (TENEX C Shell) are different shells with different quirks and syntax.

Bash (borne again shell) is the default bog standard shell on Linux. Bash itself is an improved version of sh.

Old versions of MacOS used TCSH as the default shell but recently switched to ZSH which is more or less similar with Bash and sh. The choice for TCSH is probably related to code imported from FreeBSD where TCSH was the default having recently changed to SH.

For the record, this is how you do redirection on TCSH:

$ ls -l /bin/bash /bing/other > out
ls: /bing/other: No such file or directory


$ ls -l /bin/bash /bing/other  > & out
(combine stdout and stderr)


$ (ls -l /bin/bash /bing/other  > out) > & err
(direct stdout to 'out' and stderr to 'err')

Source: Redirection tcsh

1 Like

Interesting information, thank you very much kind sir! So, it would probably be a good idea to switch to ZSH to avoid annoyances like this one.

I alsways assumed TCSH was what newer Macs were using, due to my Mac from 2019 having it (16") while the Macs of a few colleagues of mine (also 2019, but a bit older) were not having it.