Changes between Initial Version and Version 1 of waue/2009/0707


Ignore:
Timestamp:
Jul 7, 2009, 2:53:18 PM (15 years ago)
Author:
waue
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • waue/2009/0707

    v1 v1  
     1
     2 = shell 裡 for ... in 與 運算 的應用 =
     3
     4 * example 1 : 批次殺程序
     5
     6{{{
     7#!/bin/bash
     8
     9#str=$(ps axw -eo pid,command | grep "org.apache.catalina.startup.Bootstrap" | grep "start" | awk '{print $1}')
     10
     11str=$(ps axw -eo pid,command |\
     12 grep "apache" | grep "start" |\
     13 awk '{print $1}')
     14echo "str = $str"
     15
     16count=1
     17for i in $str
     18do
     19 echo "string[$count]= $i"
     20 echo "kill -9 $i"
     21 count=$(($count+1))
     22done
     23
     24}}}
     25
     26 * example 2 : 批次改檔名
     27
     28{{{
     29cd ~
     30for i in *.[tT][iI][fF]; do
     31#若目錄內無 .tif 檔案 $i 會傳回 "*.[tT][iI][fF]"
     32if [ "$i" != "*.[tT][iI][fF]" ]; then
     33#取得副檔名
     34subname="`echo $i | awk -F '.' '{print $NF}'`"
     35#取得主檔名
     36filename="`echo $i | sed -e s/\.${subname}$//`"
     37#將 .tif 轉成 .pdf
     38#tiff2pdf -o "${filename}.pdf" "$i"
     39mv ${filename}.tif ${filename}.pdf
     40#若執行成功則刪除 .tif 檔案
     41if [ $? -eq 0 ]; then
     42rm -rf $i
     43fi
     44fi
     45done
     46}}}