Ubuntu16.04
forの出力が末尾のclient in */; do
スラッシュを生成しなくても、ループ内のファイルに対して時間テストを実行しながら$ client変数をエコーすると、後続のスラッシュが発生します。
cd "$wDir"
for client in */; do
cd "$wDir"/"$client";
#-- check to see if any .csv files exists
if ls *.csv &>/dev/null; then
for csvfile in *.csv; do
if test $(find "$csvfile" -mmin +2880); then
echo "$client has files older than 2 days ..." >> "staleFtpAccts"
fi
done
fi
done
スクリプトを実行すると、次のように$ client変数の後に/が配置されます。
root@me /home/frank # bash script.sh
Start ...
000029_000020/ has files older than 2 days ...
#--
Finished ...
Start ...
000033_000040/ has files older than 2 days ...
#--
Finished ...
Start ...
000033_000041/ has files older than 2 days ...
#--
Finished ...
Start ...
000033_000042/ has files older than 2 days ...
#--
Finished ...
Start ...
000033_000043/ has files older than 2 days ...
#--
Finished ...
これが私が追求した結果です...
root@me /home/frank # bash script.sh
Start ...
000029_000020 has files older than 2 days ...
#--
Finished ...
Start ...
000033_000040 has files older than 2 days ...
#--
Finished ...
Start ...
000033_000041 has files older than 2 days ...
#--
Finished ...
Start ...
000033_000042 has files older than 2 days ...
#--
Finished ...
Start ...
000033_000043 has files older than 2 days ...
#--
Finished ...
答え1
この試みPOSIX パラメータ拡張:
echo "${client%/}"
だから
echo "${client%/} has files older than 2 days ..."
パラメータ拡張拡張パラメータ:、、
"$foo"
."$1"
を使用して文字列または配列操作を実行できます。"${file%.mp3}"
、、"${0##*/}", "${files[@]: -4}"
。いつも引用してください。望むより:http://mywiki.wooledge.org/BashFAQ/073そしてman bashの「パラメータ拡張」。また見てくださいhttp://wiki.bash-hackers.org/syntax/pe。