Tag Info

Hot answers tagged

6

Alias substitution is only performed when reading lines from interactive sources. So the second alias is not affected by the first, hence the literal replacement. Perhaps something similar: PACMAN=pacman if [ -f /usr/bin/pacmatic ]; then PACMAN=pacmatic fi # Colorized Pacman output alias pacman="${PACMAN} --color auto" This'll set 'pacman' to the ...


3

A shell alias behaves pretty similarly to a #define, i.e. redefining a shell alias would override the previous one. I'm not sure what would be the Right WayTM, but one approach would be making use a shell function that accepts parameters and using that to create an alias. Your code snippet could be rewritten as: if [ -f /usr/bin/pacmatic ]; then ...


3

How about using brace expansions? $ ls -ld /{,usr/{,bin/{,tee}}} drwxr-xr-x 23 root root 4096 Mar 7 06:57 / drwxr-xr-x 10 root root 4096 Jan 9 2013 /usr/ drwxr-xr-x 2 root root 40960 Apr 9 23:57 /usr/bin/ -rwxr-xr-x 1 root root 26176 Nov 19 2012 /usr/bin/tee


3

ls -ld `echo 'path/to/file' | sed ':0 p;s!/[^/]*$!!;t0' | sort -u` sed part: :0 label 0; p print; s!p!r! replace pattern p with replacement r; /[^/]*$ search for /, then any sequence of not-/ till the end of line; replacement is empty, so just delete the match; t0 if s!!! performs a replacement, then go to label 0. Edit by OP after comments I did the ...


2

I can't think of any expansion trick or utility to do it all in one go. So a loop is the way to go. Here's some code that works under both bash and zsh, and accommodates directories with arbitrary names. ## Usage: set_directory_chain VAR FILENAME ## Set VAR to the chain of directories leading to FILENAME ## e.g. set_directory_chain a /usr/bin/env is ...


1

su executes your login shell as indicated in the login database. This is /root/zsh, which doesn't exist, so the command su fails. chsh only accepts changing the shell of a user who currently has a valid shell (listed in /etc/shells). Since /root/zsh is not accepted, chsh fails. The root user can change anyone's shell, but this test is made after the ...


1

In zsh, you can easily append to an alias by using the aliases associative array: alias pacman="${aliases[pacman]-pacman} --color auto" In other shells, you need to use the output of the alias command to find out about existing aliases. current_pacman_alias=$(alias pacman 2>/dev/null) alias pacman="${current_pacman_alias:-pacman} --color auto" While ...



Only top voted, non community-wiki answers of a minimum length are eligible