Application of eval in shell

Source: Internet
Author: User

Application of eval in shell


Eval can be used for nesting of variables


Dr=ddir$inum

Eval ssdir=$ (Echo \$ $SR)


Example:


#!/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




This article is from the "Linux" blog, so be sure to keep this source http://yangzhiming.blog.51cto.com/4849999/1727641

Application of eval in shell

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.