我只是在bash中專門學習shell腳本,我希望能夠使用gzip從目標目錄獲取文件並將它們發送到不同的目錄。我在命令行中輸入目錄。 ext是用於我想壓縮的擴展名,文件將是新的壓縮文件。 我的腳本正確地將文件拉到,往返於所需的目錄,,但我得到一個沒有這樣的文件或目錄錯誤。我如何避免這種情況?Gzip沒有這樣的文件或目錄錯誤,仍然拉鍊文件
當前代碼
cd $1
for ext in $*; do
for file in `ls *.$ext`; do
gzip -c $file > $2/$file.gz
done
done
和我的I/O
[email protected]:~/Desktop/60256$ bash myCompress /home/blackton/Desktop/ /home/blackton/ txt
ls: cannot access *./home/blackton/Desktop/: No such file or directory
ls: cannot access *./home/blackton/: No such file or directory
gzip: alg: No such file or directory
gzip: proj.txt: No such file or directory
用'find -name *「*。$分機」型F',而不是'LS * $ ext' – GMichael