Search code examples
unixcdtcsh

Difference in behavior between 2 aliased cds in unix shell


I connect to a remote computer thru VNC and use Konsole for my work. Konsole is version 2.3.3 using KDE 4.3.4. I have these two aliases:

alias ll  'ls -haltr; pwd'
alias cd  'cd \!*; ll'

which I observed to have the following behavior:

  1. When path exists, it will cd to it and also do the ll alias
  2. When path doesn't exist, it will simply say the path doesn't exist and won't do the ll anymore

Example:

Path exists

[10] % cd foo
total 14K
-rw-r-----  1 user group   913 Jun  3  2014 readme
-rw-r-----  1 user group  1.2K Dec  3  2020 report.txt
drwxr-x---  2 user group  4.0K Jan 12 17:50 ./
drwx------ 77 user group  8.0K Jun 24 11:57 ../
/home/user/foo    
[11] % 

Path doesn't exist

[10] % cd nowhere
nowhere: No such file or directory.
[11] % 

Now our department has transferred to another division and we've just started to connect remotely thru Exceed TurboX. I still use Konsole but the version is now 2.10.5 using KDE 4.10.5. I copied over the same two aliases, but I'm now observing a different behavior:

  1. When path exists, it will cd to it and also do the ll alias (basically same as #1 above)
  2. When path doesn't exist, it will attempt to cd AND still do the ll (different as #2 above)

So for #2, here's how it looks like:

[10] % cd nowhere
nowhere: No such file or directory.
total 120K
-rw-r-----  1 user group   272 Jan  6  2021 .cshrc
-rw-r-----  1 user group  1.2K Jan  6  2021 .alias
drwxr-x---  2 user group  4.0K Jan 12 17:50 ./
drwx------ 77 user group  8.0K Jun 24 11:57 ../
/home/user
[11] % 

I would like to know how to get behavior #2 of the previous working environment to this current working environment.

I've added the information on the Konsole and KDE versions because if the behavior is due to the version and there's no workaround, then I'll just be sad for the rest of my life working in this new remote desktop env. ^_^

I'm currently exploring a "check first if the path exists before doing ll" but to no avail. :'(

Edit:
The shell I'm using is tcsh
% printenv SHELL in both environments showed /bin/tcsh
And in addition:

Old environment

% echo $version
tcsh 6.17.00 (Astron) 2009-07-10 (x86_64-unknown-linux) options wide,nls,dl,al,kan,sm,rh,color,filec

New environment

% echo $version
3

Solution

  • The information in the question is still not sufficient to find out why tcsh behaves differently in the two working environments.

    The alias defines a sequence of commands (cd followed by ll) without any condition.

    alias cd  'cd \!*; ll'
    

    On one system the execution of the alias seems to stop if the cd command reports an error for currently unknown reasons.

    The correct way to prevent the execution of ll after a failed cd command would be the conditional execution of the ll command, e.g.

    alias cd  'cd \!* && ll'