how to set parameters when pipe bash script to bash
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
add a comment |
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
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
add a comment |
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
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
bash shell-script pipe
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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.
There is a problem with this, as my parameters have "-" prefix, therefore I callbash -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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
There is a problem with this, as my parameters have "-" prefix, therefore I callbash -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
add a comment |
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.
There is a problem with this, as my parameters have "-" prefix, therefore I callbash -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
add a comment |
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.
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.
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 callbash -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
add a comment |
There is a problem with this, as my parameters have "-" prefix, therefore I callbash -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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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