shell 中eval运用
eval 可用于变量的嵌套
DR=DDIR$inum
eval SSDIR=$(echo \$$SR)
范例:
#!/bin/bash
Date=`date +%Y%m%d`
SDIR1=/DATA-to-External/aa
SDIR2=/DATA-to-External/bb
SDIR3=/DATA-to-External/cc
DDIR1=/historybackup/Data-to-External/aa
DDIR2=/historybackup/Data-to-External/bb
DDIR3=/historybackup/Data-to-External/cc
for inum in `seq 1 7`
do
SR=SDIR$inum
DR=DDIR$inum
eval SSDIR=$(echo \$$SR)
eval DDDIR=$(echo \$$DR)
cd $SSDIR
for job in $(ls)
do
if [ -d $job ];then
mkdir -p $DDDIR/$Date/$job
mv $job/* $DDDIR/$Date/$job/
fi
done
done
本文出自 “linux” 博客,请务必保留此出处http://yangzhiming.blog.51cto.com/4849999/1727641
原文地址:http://yangzhiming.blog.51cto.com/4849999/1727641