how to set parameters when pipe bash script to bash












3














How to execute bash script with parameters:



./foo.sh a b c


When it's compressed (e.g. using xz).



 xzcat foo.sh | bash <<how_to_supply_here_parameters?>>


Specific usecase:



I produced very big rmlint.sh file and store it compressed:



time rmlint -o sh:stdout -c sh:hardlink|tee >( xz > rmlint.sh.xz )


Therefore I would normally execute



./rmlint.sh -d -x -p


However, file is too big to be uncompressed. Therefore I would love to do same by pipe-ing it to bash:



xzcat rmlint.sh.xz | bash ...









share|improve this question




















  • 2




    How big is this script, is it a world record? Did you use functions, or paste/copy code all over the place?
    – ctrl-alt-delor
    Dec 27 '18 at 10:08
















3














How to execute bash script with parameters:



./foo.sh a b c


When it's compressed (e.g. using xz).



 xzcat foo.sh | bash <<how_to_supply_here_parameters?>>


Specific usecase:



I produced very big rmlint.sh file and store it compressed:



time rmlint -o sh:stdout -c sh:hardlink|tee >( xz > rmlint.sh.xz )


Therefore I would normally execute



./rmlint.sh -d -x -p


However, file is too big to be uncompressed. Therefore I would love to do same by pipe-ing it to bash:



xzcat rmlint.sh.xz | bash ...









share|improve this question




















  • 2




    How big is this script, is it a world record? Did you use functions, or paste/copy code all over the place?
    – ctrl-alt-delor
    Dec 27 '18 at 10:08














3












3








3







How to execute bash script with parameters:



./foo.sh a b c


When it's compressed (e.g. using xz).



 xzcat foo.sh | bash <<how_to_supply_here_parameters?>>


Specific usecase:



I produced very big rmlint.sh file and store it compressed:



time rmlint -o sh:stdout -c sh:hardlink|tee >( xz > rmlint.sh.xz )


Therefore I would normally execute



./rmlint.sh -d -x -p


However, file is too big to be uncompressed. Therefore I would love to do same by pipe-ing it to bash:



xzcat rmlint.sh.xz | bash ...









share|improve this question















How to execute bash script with parameters:



./foo.sh a b c


When it's compressed (e.g. using xz).



 xzcat foo.sh | bash <<how_to_supply_here_parameters?>>


Specific usecase:



I produced very big rmlint.sh file and store it compressed:



time rmlint -o sh:stdout -c sh:hardlink|tee >( xz > rmlint.sh.xz )


Therefore I would normally execute



./rmlint.sh -d -x -p


However, file is too big to be uncompressed. Therefore I would love to do same by pipe-ing it to bash:



xzcat rmlint.sh.xz | bash ...






bash shell-script pipe






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 27 '18 at 11:06









SouravGhosh

493311




493311










asked Dec 27 '18 at 9:13









Grzegorz Wierzowiecki

5,2101361104




5,2101361104








  • 2




    How big is this script, is it a world record? Did you use functions, or paste/copy code all over the place?
    – ctrl-alt-delor
    Dec 27 '18 at 10:08














  • 2




    How big is this script, is it a world record? Did you use functions, or paste/copy code all over the place?
    – ctrl-alt-delor
    Dec 27 '18 at 10:08








2




2




How big is this script, is it a world record? Did you use functions, or paste/copy code all over the place?
– ctrl-alt-delor
Dec 27 '18 at 10:08




How big is this script, is it a world record? Did you use functions, or paste/copy code all over the place?
– ctrl-alt-delor
Dec 27 '18 at 10:08










1 Answer
1






active

oldest

votes


















7














You should use the -s option and -- to separate arguments you want to pass:



echo 'echo "$@"' | sh -s 3 4 5

echo 'printf "{%s}" "$0"; printf " {%s}" "$@"; echo' |
sh -s -- -d -x -p --foo=bar
{sh} {-d} {-x} {-p} {--foo=bar}


This should work with any POSIX shell, not just bash. From susv4:




-s
Read commands from the standard input.



If there are no operands and the -c option is not specified, the -s
option shall be assumed.







share|improve this answer























  • There is a problem with this, as my parameters have "-" prefix, therefore I call bash -s -d -x -p and get in return : bash: -d: invalid option ( pastebin.com/JXRiUuLR )
    – Grzegorz Wierzowiecki
    Dec 27 '18 at 10:47






  • 2




    You use the -- end of options marker, as usual. See the 2nd example.
    – mosvy
    Dec 27 '18 at 10:57










  • Thank you a lot for help and apologise for stupid overlook! You helped me to find what I was overlooking (to short sleep Today), which was -- - Thank you! Now it works perfectly!
    – Grzegorz Wierzowiecki
    Dec 27 '18 at 11:01










  • Added -- to first line of your solution as it was something I overlooked, so I hope it will help some others, who may overlook it as well
    – Grzegorz Wierzowiecki
    Dec 28 '18 at 10:42











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f491090%2fhow-to-set-parameters-when-pipe-bash-script-to-bash%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









7














You should use the -s option and -- to separate arguments you want to pass:



echo 'echo "$@"' | sh -s 3 4 5

echo 'printf "{%s}" "$0"; printf " {%s}" "$@"; echo' |
sh -s -- -d -x -p --foo=bar
{sh} {-d} {-x} {-p} {--foo=bar}


This should work with any POSIX shell, not just bash. From susv4:




-s
Read commands from the standard input.



If there are no operands and the -c option is not specified, the -s
option shall be assumed.







share|improve this answer























  • There is a problem with this, as my parameters have "-" prefix, therefore I call bash -s -d -x -p and get in return : bash: -d: invalid option ( pastebin.com/JXRiUuLR )
    – Grzegorz Wierzowiecki
    Dec 27 '18 at 10:47






  • 2




    You use the -- end of options marker, as usual. See the 2nd example.
    – mosvy
    Dec 27 '18 at 10:57










  • Thank you a lot for help and apologise for stupid overlook! You helped me to find what I was overlooking (to short sleep Today), which was -- - Thank you! Now it works perfectly!
    – Grzegorz Wierzowiecki
    Dec 27 '18 at 11:01










  • Added -- to first line of your solution as it was something I overlooked, so I hope it will help some others, who may overlook it as well
    – Grzegorz Wierzowiecki
    Dec 28 '18 at 10:42
















7














You should use the -s option and -- to separate arguments you want to pass:



echo 'echo "$@"' | sh -s 3 4 5

echo 'printf "{%s}" "$0"; printf " {%s}" "$@"; echo' |
sh -s -- -d -x -p --foo=bar
{sh} {-d} {-x} {-p} {--foo=bar}


This should work with any POSIX shell, not just bash. From susv4:




-s
Read commands from the standard input.



If there are no operands and the -c option is not specified, the -s
option shall be assumed.







share|improve this answer























  • There is a problem with this, as my parameters have "-" prefix, therefore I call bash -s -d -x -p and get in return : bash: -d: invalid option ( pastebin.com/JXRiUuLR )
    – Grzegorz Wierzowiecki
    Dec 27 '18 at 10:47






  • 2




    You use the -- end of options marker, as usual. See the 2nd example.
    – mosvy
    Dec 27 '18 at 10:57










  • Thank you a lot for help and apologise for stupid overlook! You helped me to find what I was overlooking (to short sleep Today), which was -- - Thank you! Now it works perfectly!
    – Grzegorz Wierzowiecki
    Dec 27 '18 at 11:01










  • Added -- to first line of your solution as it was something I overlooked, so I hope it will help some others, who may overlook it as well
    – Grzegorz Wierzowiecki
    Dec 28 '18 at 10:42














7












7








7






You should use the -s option and -- to separate arguments you want to pass:



echo 'echo "$@"' | sh -s 3 4 5

echo 'printf "{%s}" "$0"; printf " {%s}" "$@"; echo' |
sh -s -- -d -x -p --foo=bar
{sh} {-d} {-x} {-p} {--foo=bar}


This should work with any POSIX shell, not just bash. From susv4:




-s
Read commands from the standard input.



If there are no operands and the -c option is not specified, the -s
option shall be assumed.







share|improve this answer














You should use the -s option and -- to separate arguments you want to pass:



echo 'echo "$@"' | sh -s 3 4 5

echo 'printf "{%s}" "$0"; printf " {%s}" "$@"; echo' |
sh -s -- -d -x -p --foo=bar
{sh} {-d} {-x} {-p} {--foo=bar}


This should work with any POSIX shell, not just bash. From susv4:




-s
Read commands from the standard input.



If there are no operands and the -c option is not specified, the -s
option shall be assumed.








share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 28 '18 at 10:41









Grzegorz Wierzowiecki

5,2101361104




5,2101361104










answered Dec 27 '18 at 9:45









mosvy

6,0211425




6,0211425












  • There is a problem with this, as my parameters have "-" prefix, therefore I call bash -s -d -x -p and get in return : bash: -d: invalid option ( pastebin.com/JXRiUuLR )
    – Grzegorz Wierzowiecki
    Dec 27 '18 at 10:47






  • 2




    You use the -- end of options marker, as usual. See the 2nd example.
    – mosvy
    Dec 27 '18 at 10:57










  • Thank you a lot for help and apologise for stupid overlook! You helped me to find what I was overlooking (to short sleep Today), which was -- - Thank you! Now it works perfectly!
    – Grzegorz Wierzowiecki
    Dec 27 '18 at 11:01










  • Added -- to first line of your solution as it was something I overlooked, so I hope it will help some others, who may overlook it as well
    – Grzegorz Wierzowiecki
    Dec 28 '18 at 10:42


















  • There is a problem with this, as my parameters have "-" prefix, therefore I call bash -s -d -x -p and get in return : bash: -d: invalid option ( pastebin.com/JXRiUuLR )
    – Grzegorz Wierzowiecki
    Dec 27 '18 at 10:47






  • 2




    You use the -- end of options marker, as usual. See the 2nd example.
    – mosvy
    Dec 27 '18 at 10:57










  • Thank you a lot for help and apologise for stupid overlook! You helped me to find what I was overlooking (to short sleep Today), which was -- - Thank you! Now it works perfectly!
    – Grzegorz Wierzowiecki
    Dec 27 '18 at 11:01










  • Added -- to first line of your solution as it was something I overlooked, so I hope it will help some others, who may overlook it as well
    – Grzegorz Wierzowiecki
    Dec 28 '18 at 10:42
















There is a problem with this, as my parameters have "-" prefix, therefore I call bash -s -d -x -p and get in return : bash: -d: invalid option ( pastebin.com/JXRiUuLR )
– Grzegorz Wierzowiecki
Dec 27 '18 at 10:47




There is a problem with this, as my parameters have "-" prefix, therefore I call bash -s -d -x -p and get in return : bash: -d: invalid option ( pastebin.com/JXRiUuLR )
– Grzegorz Wierzowiecki
Dec 27 '18 at 10:47




2




2




You use the -- end of options marker, as usual. See the 2nd example.
– mosvy
Dec 27 '18 at 10:57




You use the -- end of options marker, as usual. See the 2nd example.
– mosvy
Dec 27 '18 at 10:57












Thank you a lot for help and apologise for stupid overlook! You helped me to find what I was overlooking (to short sleep Today), which was -- - Thank you! Now it works perfectly!
– Grzegorz Wierzowiecki
Dec 27 '18 at 11:01




Thank you a lot for help and apologise for stupid overlook! You helped me to find what I was overlooking (to short sleep Today), which was -- - Thank you! Now it works perfectly!
– Grzegorz Wierzowiecki
Dec 27 '18 at 11:01












Added -- to first line of your solution as it was something I overlooked, so I hope it will help some others, who may overlook it as well
– Grzegorz Wierzowiecki
Dec 28 '18 at 10:42




Added -- to first line of your solution as it was something I overlooked, so I hope it will help some others, who may overlook it as well
– Grzegorz Wierzowiecki
Dec 28 '18 at 10:42


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f491090%2fhow-to-set-parameters-when-pipe-bash-script-to-bash%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Сан-Квентин

Алькесар

Josef Freinademetz