2017-04-27 6 views
2

私は引数を渡してそれを元に戻そうとしています。私はできません。|を扱うときに+引数を渡すには? (パイプ)?

#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 

私の目標は、私は私のスクリプト内で渡された私の引数にアクセスできるようにすることです試してみてください#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 

をお試しください:yellowredを、​​を

[0]:bashの

[1]:黄色

[2]:赤

[3]:緑色


bashrc.sh

#!/bin/bash 

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

echo "There $# arguments" 

.... 

どうすれば達成できますか?

答えて

1

-sスイッチ用途:man bash 1として

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

yellow 
red 
green 
There 3 arguments 

-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. 
関連する問題