我的腳本正在讀取和顯示id3標籤。我試圖讓它回聲未知,如果該字段是空白,但每個如果我嘗試的聲明不會工作。 id3標籤是一個固定的大小,所以它們永遠不會爲空,但如果沒有任何值,它們將被填充空白區域。 I.E標題標籤的長度爲30個字符。到目前爲止,我已經試過測試字符串在Bash中是否有非空白字符
echo :$string: #outputs spaces between the 2 ::
if [ -z "$string" ] #because of white space will always evaluate to true
x=echo $string | tr -d ' '; if [ -z "$string" ];
#still計算結果爲真實的,但回聲:$ X:它的回聲::
腳本
#!bin/bash
echo "$# files";
while [ "$i" != "" ];
do
TAG=`tail -c 128 "$i" | head -c 3`;
if [ $TAG="TAG" ]
then
ID3[0]=`tail -c 125 "$1" | head -c 30`;
ID3[1]=`tail -c 95 "$1" | head -c 30`;
ID3[2]=`tail -c 65 "$1" | head -c 30`;
ID3[3]=`tail -c 35 "$1" | head 4`;
ID3[4]=`tail -c 31 "$i" | head -c 28`;
for i in "${ID3[@]}"
do
if [ "$(echo $i)" ] #the if statement mentioned
then
echo "N/A";
else
echo ":$i:";
fi
done
else
echo "$i does not have a proper id3 tag";
fi
shift;
done
'-z「$ x」'當然? – 2012-03-19 09:37:43
Michal Politowski:'-z' \t表示操作數的長度爲零 – 2012-03-19 10:03:43
@ Peter.O:是的,$ x是應該測試的字符串,而不是$ string。 – ams 2012-03-19 10:10:38