14.shell script learning

Simple execution trace will show that each command is executed Shell to
sh -x delete.sh

Find and replace
grep
Sed -i "S / t_rs_customer / t_rs_customer_bak / G" t_rs_customer_bak.sql 

Using cut selected fields
cut -d: -f l, 5 / etc / the passwd
cut -d: -f. 6 / etc / the passwd

Use awk rearrange field
defaults a blank fields are separated
awk '{Print $. 1}' delete.sh
awk '{Print $. 1, $. 3}' delete.sh
set the field separator
awk -F: '{print $ 1 , $ 3}' / etc / passwd

Calculate the number of lines, words and characters
wc -l, wc -w, wc -c

if-elif-else-fi语句
if pipeline
   [pipeline ... ]
then
   statements-if-true-1
[ elif pipeline
   [pipeline ... ]
then
   statements-if-true-2
]
[ else
   statements-if-all-else-fails
]
fi

case statement
case var in
exp. 1-) command ;; body. 1
exp-2) 2 ;; command
...
*) command thereof ;;
Esac

for循环
for i in {1..10}
do
   echo $i
done
i=1
while(($i<100))
do
    if(($i%4==0))
    then
        echo $i
    fi
    i=$(($i+1))
done

It refers to a single function program code section for performing a number of individual work fully defined

Guess you like

Origin www.cnblogs.com/allenhu320/p/11284552.html