幾個簡單的shell指令碼

2021-07-14 22:47:52 字數 1354 閱讀 2213

今天寫了個linux shell指令碼,通過不同命令列引數來執行不同操作,使用到了linux shell的命令列引數輸入和case語句,此篇做備忘錄吧。

#!/bin/sh

case $1 in

webp) cd webp;;

jpeg) cd jpeg;;

zlib) cd zlib;;

lz) cd lz;;

*) echo "invalid parameter!"

exit -1

;;esac

make clean

make

make install

cd ..

exit

為了進行交叉編譯,需要將.dll轉化為.def和.a檔案,所以我寫了個批量處理的指令碼,如下:

#!/bin/bash

#資料夾是否存在

if [ ! -d lib ]; then

mkdir lib

fifor file in $(ls *.dll)

do #echo $file

i686-w64-mingw32-dlltool --dllname $file --def $.def --output-lib ./lib/$.a

done

exit 0

#!/bin/bash

image_dir=/tmp/image

curr_dir=$(pwd)

#資料夾是否存在

if [ ! -d $image_dir ]; then

mkdir $image_dir

fi#資料夾是否為空

if [ -n "`ls -a $image_dir`" ]; then

cd $image_dir

#將當前資料夾中的所有檔案打包壓縮,排除當前目錄和父目錄

tar -czvf ./image.tar.gz --exclude . --exclude .. *

cp -f image.tar.gz $curr_dir/image/

rm -rf *

else

echo "dir $image_dir is empty!"

fiexit 0

接下來來乙個1到100求和的:

#!/bin/sh

x=1sum=0

while [ "$x" -le 100 ]; do

sum=$(($sum+$x))

x=$(($x+1))

done

echo $sum

exit 0

幾個簡單的shell指令碼

bin bash shows system date echo date f date f顯示的是當前日期 date w顯示的是當前週數 exit 0 2 比較兩個值得大小 bin bash compare the size of the two numbers read p please inpu...

簡單的幾個shell指令碼二

1 查詢乙個檔案中空白行行數。bin bash file etc inittab if e file then echo no file exit 8 fiif grep file dev null then echo total blank line grep file wc l else ech...

shell指令碼幾個練習

1編寫乙個shell指令碼,它把第二個位置引數及其以後的各個引數指定的檔案複製到第乙個位置引數指定的目中。bin bash dir 1 shift for i in docp i done 2.編寫乙個shell指令碼,顯示當天日期,查詢給定的某使用者是否在系統中工作。如果在系統中,就發乙個問候給他...