I am trying below alias in cshell:
alias sll 'ls -l \!* | grep -oE '[^ ]+$' | paste -s | xargs ls -l'
For this CSH says, Illegal variable name.
If I use \$
, alias will be set without any error. But when I use this alias, I get, grep: Invalid regular expression
PS:
- The aim of this alias is to achieve
ls -Ll <filenames>
but with
full path of the file the symbolic link references. - The RHS part of alias works fine as standalone command.
- Instead of egrep (grep -E), I tried
awk '{print $NF}'
. Even for
this, CSH gives the error: NF undefined variable.
Best Answer
Check your single quotes. Single quotes don't magically nest.
That's still flawed for several reasons:
[^ ]
, that won't work for file or link target names that contain spaces.xargs
, that won't work with file/target names containing apostrophes, backslashes, double quotes, other types of blanks.ls
is a relative path to the current directory, while symlinks are resolved relative to the path of the symlink file (if you have aa/b/c -> d
link, that's toa/b/d
, notd
in the current directory).total <n>
line of the output ofls
.ls -lL
(may be what you want though).With
zsh
, you could make it:The
:A
modifier expands symlinks to their canonical absolute path.A quasi-equivalent on GNU systems: