从另一个脚本呼叫一个Bash脚本传递给它的参数加上引号和空格 [英] Calling one Bash script from another Script passing it arguments with quotes and spaces

查看:167
本文介绍了从另一个脚本呼叫一个Bash脚本传递给它的参数加上引号和空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    echo "TestScript1 Arguments:"
    echo "$1"
    echo "$2"
    echo "$#"
    ./testscript2 $1 $2

TestScript2如下:

    echo "TestScript2 Arguments received from TestScript1:"
    echo "$1"
    echo "$2"
    echo "$#"

当我通过以下方式执行testscript1:

    ./testscript1 "Firstname Lastname" testmail@domain.com  

所需的输出应该是:

    TestScript1 Arguments:  
    Firstname Lastname  
    testmail@domain.com  
    2
    TestScript2 Arguments received from TestScript1:  
    Firstname Lastname  
    testmail@domain.com  
    2  

但是实际的输出是:

    TestScript1 Arguments:  
    Firstname Lastname  
    testmail@domain.com  
    2
    TestScript2 Arguments received from TestScript1:  
    Firstname
    Lastname      
    3  

我要如何解决这个问题?我想获得所需的输出,而不是实际的输出。

How do i solve this problem? I want to get the desired output instead of the actual output.

推荐答案

引用您的ARGS在Testscript 1:

Quote your args in Testscript 1:

echo "TestScript1 Arguments:"
echo "$1"
echo "$2"
echo "$#"
./testscript2 "$1" "$2"

这篇关于从另一个脚本呼叫一个Bash脚本传递给它的参数加上引号和空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆