Files
lk/shell/bash_tips.md

1005 B

title, tags
title tags
Bash tips
shell
comfy
bash

This & That

Refer to 'that last thing', and 'the first thing':

fortune -l > file1
cat !$  | tr -d u > file2
cat file1 !$
diff !^ !$

NB: this can go wrong:

ls -l file1 file2
cat !^

NB: this only works when running bash interactively, never in scripts.

Lists

You can put a list inside any bash argument, and bash will expand that part into a new argument.

echo file {one,two,three}.txt
echo file-{one,two,three}.txt
touch !$

Look at text files:

ls *.{txt,md}

Look at size of jpg or png files in the img/ directory:

du img/*.{jpg,png}

Automatic Lists

echo {a..d}
echo Archive_{B..E}

Using multiple lists works fine.

mkdir first second third
echo {first,second,third}/file_{1..3}.txt
x={first,second,third}/file_{1..3}.txt
echo $x
echo {first,second,third}/file_{1..3}.txt
x="$(!!)"
echo $x
for file in $x ; do fortune > $file ; done