カスタム列を使用してlsコマンドを拡張する方法

カスタム列を使用してlsコマンドを拡張する方法

ls -lカスタム列でコマンドを変更できるかどうか疑問に思います。

たとえば、この列に$(CustomCommand FILE)

ベストアンサー1

これは非常に基本的な概念証明です。特に強力ではありませんが(たとえば、空白のあるファイル名は壊れる可能性があります)、アイデアを得ます。

$ export CustomCommand=file
$ alias ls=/tmp/test/myls
$ ls
a  b  c  myls
$ ls -l
-rw-rw-r-- 1 steve steve   0 Sep 22 19:17 a a: empty
-rw-rw-r-- 1 steve steve   0 Sep 22 19:17 b b: empty
-rw-rw-r-- 1 steve steve   0 Sep 22 19:17 c c: empty
-rwxr-xr-x 1 steve steve 127 Sep 22 19:18 myls myls: POSIX shell script,     ASCII text executable
$ cat /tmp/test/myls
#!/bin/sh
if [ "$1" = "-l" ]
then
 shift
 ls -l $* | awk 'NF>2{ printf "%s ",$0 ; system("$CustomCommand " $NF) }'
else
 ls $*
fi
$

おすすめ記事