how to set parameters when pipe bash script to bash












2














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




















  • 1




    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
    4 hours ago
















2














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




















  • 1




    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
    4 hours ago














2












2








2







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 3 hours ago









SouravGhosh

437311




437311










asked 5 hours ago









Grzegorz Wierzowiecki

5,2051361104




5,2051361104








  • 1




    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
    4 hours ago














  • 1




    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
    4 hours ago








1




1




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
4 hours ago




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
4 hours ago










1 Answer
1






active

oldest

votes


















3














You should use the -s option:



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
    3 hours ago










  • You use the -- end of options marker, as usual. See the 2nd example.
    – mosvy
    3 hours ago










  • 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
    3 hours ago











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









3














You should use the -s option:



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
    3 hours ago










  • You use the -- end of options marker, as usual. See the 2nd example.
    – mosvy
    3 hours ago










  • 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
    3 hours ago
















3














You should use the -s option:



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
    3 hours ago










  • You use the -- end of options marker, as usual. See the 2nd example.
    – mosvy
    3 hours ago










  • 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
    3 hours ago














3












3








3






You should use the -s option:



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:



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 3 hours ago

























answered 4 hours ago









mosvy

5,5191323




5,5191323












  • 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
    3 hours ago










  • You use the -- end of options marker, as usual. See the 2nd example.
    – mosvy
    3 hours ago










  • 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
    3 hours ago


















  • 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
    3 hours ago










  • You use the -- end of options marker, as usual. See the 2nd example.
    – mosvy
    3 hours ago










  • 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
    3 hours ago
















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
3 hours ago




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
3 hours ago












You use the -- end of options marker, as usual. See the 2nd example.
– mosvy
3 hours ago




You use the -- end of options marker, as usual. See the 2nd example.
– mosvy
3 hours ago












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
3 hours ago




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
3 hours ago


















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

What visual should I use to simply compare current year value vs last year in Power BI desktop

How to ignore python UserWarning in pytest?

Alexandru Averescu