Artificial intelligent assistant

pass piped variable to perl oneliner if you have something like: find . -d -maxdepth 1 | wc -l | perl ... what ways do you have to tell perl to take this variable that's coming its way and substract 1? I try to substract 1 since find is counting 1 too much.

Perl would be overkill here.


find . -maxdepth 1 -mindepth 1 | wc -l


(better use `grep -c /` instead of `wc -l` in case some filenames have newline characters in them).

Or with GNU `ls`:


ls -A | wc -l


With `zsh`:


f=(*(D))
echo $#f


To remove one:


... | tail -n +2 | wc -l


Or:


n=$(... | wc -l); echo "$(($n - 1))"


With perl, you can use the `-n` or `-p` flag:


... | perl -lpe '--$_'


Above that `--$_` expression is evaluated and the content of the `$_` variable printed for each line of input.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 1aed64bbbf37aceb73f3ef947bcff836