2017-04-27 1 views
2

저는 인수를 전달하여 다시 인쇄하려고합니다. 나는 할 수 없다.| 처리 할 때 + 인수를 전달하는 방법 | (파이프)?

시도 # 1

curl www.site.com/bash/bashrc.sh | bash 

    % Total % Received % Xferd Average Speed Time Time  Time Current 
           Dload Upload Total Spent Left Speed 
100 3391 100 3391 0  0 66809  0 --:--:-- --:--:-- --:--:-- 67820 
There 0 arguments 

시도 # 2

curl www.site.com/bash/bashrc.sh | bash yellow red green 

bash: yellow: No such file or directory 
    % Total % Received % Xferd Average Speed Time Time  Time Current 
           Dload Upload Total Spent Left Speed 
100 3391 100 3391 0  0 130k  0 --:--:-- --:--:-- --:--:-- 132k 
(23) Failed writing body 

내 목표는 내 스크립트 내부에 전달 내 인수에 액세스 할 수 있습니다 : yellow, redgreen

[0] 떠들썩한 파티

[1] : 황색

[2] : 레드

[3] : 녹색


bashrc.sh

#!/bin/bash 

for i in [email protected] 
do echo $i 
done 

echo "There $# arguments" 

.... 

어떻게 해결할 수 있습니까?

답변

1

사용 -s 스위치 :

curl www.site.com/bash/bashrc.sh | bash -s yellow red green 

yellow 
red 
green 
There 3 arguments 

으로 man bash 당 :

-s If the -s option is present, or if no arguments remain after option processing, 
    then commands are read from the standard input. This option allows the positional 
    parameters to be set when invoking an interactive shell.