【问题标题】:How to pass an argument in a Bash script?如何在 Bash 脚本中传递参数?
【发布时间】:2020-09-04 05:53:52
【问题描述】:

我正在运行脚本

#!/bin/bash -xv

billseqno=`sqlplus -s /@prod <<EOF
set heading off
set serveroutput off
select max(billseqno) from bc_run where control_group_ind is null;
EOF`

echo "$billseqno"


shark=`rsync --stats --dry-run -ax bill@shark:/home/$billseqno/ /home/temp/ | grep -i "number of files transferred" | cut -c30-`

其中$billseqno 表示文件夹名称,它是一个数字。

我的问题是$billseqno 的值没有传递给rsync 路径。

有什么建议吗?

谢谢

【问题讨论】:

    标签: linux bash unix arguments rsync


    【解决方案1】:

    我建议您将 SQL 查询更改为如下:

    billseqno=$( sqlplus -s replacethis/@prod <<-EOF
        set pagesize 0;
        set feedback off;
        set verify off;
        set heading off;
        select max(billseqno) 
        from bc_run 
        where control_group_ind is null;
        exit;
    EOF )
    
    
    shark=$(rsync --stats --dry-run -ax bill@shark:/home/"$billseqno"/ /home/temp/ | grep -i "number of files transferred" | cut -c30-)
    

    【讨论】:

      【解决方案2】:

      您可以尝试使用

      shark=$(rsync --stats --dry-run -ax bill@shark:/home/"${billseqno}"/ /home/temp/ | grep -i "number of files transferred" | cut -c30-)
      

      看看

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-02-12
        • 1970-01-01
        • 2012-01-23
        • 2013-06-18
        • 2014-10-09
        • 2011-10-10
        相关资源
        最近更新 更多