shell循环数组 获取文件扩展名

array_name=(
    value0
    value1
    value2
    value3
    )

 

a=("Fdf" "df" "fd")
for str in ${a[@]};do
echo $str
done
while read line
do
echo $line
done  < filename

 

cat filename | while read line
do
echo $line
done

 

for  line  in  `cat filename`
do
echo ${line}
done
basename example.tar.gz .tar.gz
# => example
 
FILE="example.tar.gz"
 
echo "${FILE%%.*}"
# => example
 
echo "${FILE%.*}"
# => example.tar
 
echo "${FILE#*.}"
# => tar.gz
 
echo "${FILE##*.}"
# => gz
 
# 在bash中可以这么写
filename=$(basename "$fullfile")
extension="${filename##*.}"
filename="${filename%.*}"

 

 

 

 

你可能感兴趣的:(shell循环数组 获取文件扩展名)