WelcomeUser Guide
ToSPrivacyCanary
DonateBugsLicense

©2025 Poal.co

968

I'm too much of a smooth brain to figure what I'm doing wrong here. I have the following in my bashrc:

alias ls="command ls --color=always --classify -v -C --group-directories-first --show-control-chars --sort=extension"

cd () { command cd "$@" && ls ; }

Now, when I "cd ~/some/dir", my customized view is properly displayed. If I manually 'ls' in that dir or any other dir, my customized view is lost. Any ideas what could cause that?

While I have your ear, somewhat off topic, why is it that when I write the 'ls' alias as a function, bash shits itself? When I write it like so:

ls () { command ls --color=always --classify -v -C --group-directories-first --show-control-chars --sort=extension ; }

bash complains:

bash: /home/FreedomLover/.bashrc: line 106: syntax error near unexpected token('`

bash: /home/FreedomLover/.bashrc: line 106: 'ls () { command ls --color=always --classify -v -C --group-directories-first --show-control-chars --sort=extension' ; }

Prost.

Ed: I forgot to mention that 'alias ls' says:

ls='ls --color=auto'

I'm too much of a smooth brain to figure what I'm doing wrong here. I have the following in my bashrc: `alias ls="command ls --color=always --classify -v -C --group-directories-first --show-control-chars --sort=extension"` `cd () { command cd "$@" && ls ; }` Now, when I "cd ~/some/dir", my customized view is properly displayed. If I manually 'ls' in that dir or any other dir, my customized view is lost. Any ideas what could cause that? While I have your ear, somewhat off topic, why is it that when I write the 'ls' alias as a function, bash shits itself? When I write it like so: `ls () { command ls --color=always --classify -v -C --group-directories-first --show-control-chars --sort=extension ; }` bash complains: `bash: /home/FreedomLover/.bashrc: line 106: syntax error near unexpected token `('` `bash: /home/FreedomLover/.bashrc: line 106: 'ls () { command ls --color=always --classify -v -C --group-directories-first --show-control-chars --sort=extension' ; }` Prost. Ed: I forgot to mention that 'alias ls' says: `ls='ls --color=auto'`

(post is archived)

When you fully grok this, you will be enlightened.

[–] 0 pt (edited )

So if I understand the man page correctly, what I read before was true. 'command' prevents recursions, at least with functions.

Also, if I understand your first comment correctly, since I am the sole user of my box, would a check for an interactive shell before applying a modded cd/ls command be ok? Something in the spirit of:

[ "-t0" ] && blah () { command ... ; }?

If the check succeeds, that shouldn't be applied scripts, right?

[–] [deleted] 1 pt (edited )

Instead of aliasing ls with ls, it's a better idea to use a command which isn't in use. Run top to look at all processes running under your username. Now consider, any one of those may be trying to grep ls and it's expecting a standardized output. Sooner or later, this is going to bite you, and it's going to be a pain to troubleshoot.

Alias as something like

alias boobs="ls --blah --blah --blah"

instead.

If you want to try and figure out how to do it the way you want to do it, that should be an interesting exercise, but I'm not going to encourage poor Unix-Fu by telling you how to do it. You can probably hang yourself just fine without my advice.

[–] 0 pt

Fair enough. Your advice is reasonable and simple. Remembering a new alias is cheaper than fucking my box up. TY.