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
    2 days ago
















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
    2 days ago














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 yesterday









SouravGhosh

455311




455311










asked 2 days ago









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
    2 days ago














  • 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
    2 days ago








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
2 days 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
2 days ago










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
    yesterday






  • 2




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










  • 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
    yesterday










  • 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
    23 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









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
    yesterday






  • 2




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










  • 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
    yesterday










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
















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
    yesterday






  • 2




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










  • 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
    yesterday










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














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









Grzegorz Wierzowiecki

5,2101361104




5,2101361104










answered 2 days ago









mosvy

5,8781325




5,8781325












  • 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
    yesterday






  • 2




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










  • 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
    yesterday










  • 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
    23 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
    yesterday






  • 2




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










  • 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
    yesterday










  • 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
    23 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
yesterday




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
yesterday




2




2




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




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












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
yesterday




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
yesterday












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




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
23 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

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas