Shell 脚本攻略-命令行之乐

2018-03-19  本文已影响0人  羊陆之交

Cat

find

xargs

Script

args.txt

arg1
arg2
arg3

test.sh

#!/bin/bash
echo $* '#'

Output

arg1 arg2 #
arg3 #

Note

tr

是转换 (translate) 的缩写。

sort

uniq

基于字符切分字符串

Script

#!/bin/bash
name=shell.cook.book
head1=${name%.*}
head2=${name%%.*}

echo head1: $head1
echo head2: $head2

name2=www.google.com
tail1=${name2#*.}
tail2=${name2##*.}

echo tail1: $tail1
echo tail2: $tail2

Output

head1: shell.cook
head2: shell
tail1: google.com
tail2: com

Note

rename

并行运行多个命令

#!/bin/bash
pids=()
for file in file1.txt file2.txt
do
        md5 $file &
        pids+=("$!")
done

wait ${pids[@]}
上一篇下一篇

猜你喜欢

热点阅读