shell字串練習

2021-09-25 17:36:30 字數 661 閱讀 6184

#!/bin/bash

# $1 : path and filetype

lsif [ $# = 0 ]//如果使用者使用命令時沒有傳入引數,這裡進行判斷,引數個數為0,則列印相關資訊並退出

then

echo " please input the file change type"

exit 0

else

type=$1//若輸入,則將第乙個引數賦給 type

fideclare -i count=0

value3=`ls *.$type`//儲存當前目錄下的所有type型別檔案的名字,這裡是反引號,功能懂得都懂,不懂看我其它文章

echo "$value3"

for a in $value3//進行迴圈改名 採用 mv

do mv $a $count.$type

count=$count+1

done

ls

注釋已經寫的很詳細了,這裡希望提醒大家一點,有時候要多採用聰明的辦法,先把他做出來再談高階的,然後***mv $a cou

nt

.count.

count.

type***這裡我搞了半天,之前不知道怎麼轉換成相同型別檔案,老師跟我說了,一下子就解決了,還是要問老師喲

字串練習

模擬tirm 方法 去除字串兩段的空格 思路 定義兩個變數 start end 分別從字串的兩段對字串進行逐個字元的判斷,當出現不是空格的字元時停止判斷,整個過程中保持 start end import com.ivan.util.systemutil public class practiseon...

字串練習

1,統計乙個字串中個字元的百分比 如輸入字串asdfs a 20 s 40 d 20 f 20 include include void percentage char str,int len if str str 判斷下乙個字元 int main int len 0 printf please i...

字串練習

字串練習 取得校園新聞的編號 num 14 5 print num 產生python文件的 com print com 產生校園新聞的一系列新聞頁 for i in range 20 print format i 練習字串內建函式 strip,lstrip,rstrip,split,count 用函...