ksh脚本中变量路径中的变量部分

问题描述 投票:0回答:1

如果过去已经回答了类似的事情,我很抱歉,但我找不到它。我正在编写一个脚本来执行一些内务处理任务,我陷入了下面的步骤。为了让您进入记录,它是一个脚本,它读取配置文件,以便能够在不同环境中将其用作标准协议。

问题出在这个代码上:

# Check if destination folder exist, if not create it.
    if [ ! -d ${V_DestFolder} ]; then # Create folder
        F_Log "${IF_ROOT} mkdir -p ${V_DestFolder}"
        ${IF_ROOT} mkdir -p ${V_DestFolder}
        continue
    fi        

    # If movement, check write permissions of destination folder.
    V_CheckIfMovement=`echo $1|grep @`
    if [ $? -eq 0 ]; then # File will be moved.
      V_DestFolder=`echo $1|awk -F"@" {'print $2'}`
      if [ ! -w ${V_DestFolder} ]; then # Destination folder IS NOT writable.
        F_Log "Destination folder ${V_DestFolder} does not have WRITE permissions. Skipping."
        continue
      fi
    fi

基本上我需要移动(在此步骤中)一些文件从一个路由到另一个路由。 它检查文件夹(从配置文件中读取的名称)是否存在,如果不存在,则检查文件夹是否具有写权限并移动文件。

在这里,您可以看到在此步骤中读取的配置文件部分:

app/tom*/instances/*/logs|+9|/.*\.gz)$/|move@/app/archive/tom*/logs

我需要说当我更改任何内容的目标的tom *时,文件被正确移动,如“test”或任何没有*的单词(应该如此)。

我需要知道的是我如何在目的地的“tom *”中使用变量。变量应该在源代码中包含相同的tom *名称,我将其用作单元格的名称。

这是因为我使用不同的tomcat单元格,引用tom7或tom8加3个字母来描述每一个。例如tom7dog或tom7cat。

linux bash variables tomcat ksh
1个回答
0
投票

你应该给shell一个评估的机会。

V_DestFolder=`echo $1|awk -F"@" {'print $2'}`
for p in ${V_DestFolder}; do
      if [ ! -w ${p} ]; then 
© www.soinside.com 2019 - 2024. All rights reserved.