Is it possible for a function to distinguish if it is run like this? “${@}”Using xargs with input from a...
How do credit card companies know what type of business I'm paying for?
At zero velocity, is this object neither speeding up nor slowing down?
My parents claim they cannot pay for my college education; what are my options?
Can an open source licence be revoked if it violates employer's IP?
Using roof rails to set up hammock
What made the Ancient One do this in Endgame?
Co-worker is now managing my team. Does this mean that I'm being demoted?
Sakkāya-Ditthi and Self-View
Why is gun control associated with the socially liberal Democratic party?
Struggling to present results from long papers in short time slots
The last tree in the Universe
Should I worry about having my credit pulled multiple times while car shopping?
Boss making me feel guilty for leaving the company at the end of my internship
Should I email my professor to clear up a (possibly very irrelevant) awkward misunderstanding?
What does the output current rating from an H-Bridge's datasheet really mean?
What should I be aware of in buying second-hand sinks and toilets?
What did the 8086 (and 8088) do upon encountering an illegal instruction?
How do I become a better writer when I hate reading?
Do items with curse of vanishing disappear from shulker boxes?
Dedicated bike GPS computer over smartphone
Why is Skinner so awkward in Hot Fuzz?
Bullying by school - Submitted PhD thesis but not allowed to proceed to viva until change to new supervisor
How to search for Android apps without ads?
Threading data on TimeSeries
Is it possible for a function to distinguish if it is run like this? “${@}”
Using xargs with input from a fileHow can a Bash script tell how it was run?Wait for key in shell script that may get piped to /bin/bashRunning repetitive task through Bash scriptIs this a bug in bash? `return` doesn't quit function if called from a pipeBash script works via terminal but not via main menuRETURN trap in Bash not executing for functionEnabling Functions in a Config file for script to run Bash Shellscriptbash: Boolean math and unary '!'I cannot get the PID for this “${@}” 1> >(2log) 2> >(2log2scr | tee >&2)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
This is my simplified script.
I am wondering if the proc() can know if it is run directly or through the runner.
#!/bin/bash
runner () {
"${@}"
}
proc() {
eval 'version=$(echo "SUCCESS: **** ${BASH_VERSION} ****")'
echo -e "$version";
return 0
}
runner proc
proc
What do you think?
bash shell-script scripting
add a comment |
This is my simplified script.
I am wondering if the proc() can know if it is run directly or through the runner.
#!/bin/bash
runner () {
"${@}"
}
proc() {
eval 'version=$(echo "SUCCESS: **** ${BASH_VERSION} ****")'
echo -e "$version";
return 0
}
runner proc
proc
What do you think?
bash shell-script scripting
add a comment |
This is my simplified script.
I am wondering if the proc() can know if it is run directly or through the runner.
#!/bin/bash
runner () {
"${@}"
}
proc() {
eval 'version=$(echo "SUCCESS: **** ${BASH_VERSION} ****")'
echo -e "$version";
return 0
}
runner proc
proc
What do you think?
bash shell-script scripting
This is my simplified script.
I am wondering if the proc() can know if it is run directly or through the runner.
#!/bin/bash
runner () {
"${@}"
}
proc() {
eval 'version=$(echo "SUCCESS: **** ${BASH_VERSION} ****")'
echo -e "$version";
return 0
}
runner proc
proc
What do you think?
bash shell-script scripting
bash shell-script scripting
edited 1 hour ago
conanDrum
asked 1 hour ago
conanDrumconanDrum
596
596
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
proc is not a separate process in your example. It's just a function, run in the same process as the main shell.
The $FUNCNAME array gives it access to its backtrace:
foo(){ bar; }
bar(){ baz; }
baz(){ proc; }
proc(){ echo "${FUNCNAME[@]}"; }
$ foo
proc baz bar foo main
So yes, it can:
case ${FUNCNAME[1]} in runner) ...
If you experiment with it, you will see that running it in a subshell / subprocess doesn't break the backtrace or affect it in any way:
foo(){ (bar &) | cat; }
=> same output
true, I clarified my title. let me check what I can do with your info. thanks a bunch
– conanDrum
1 hour ago
I've added an example test and a note about functions, backtraces & subprocesses
– mosvy
58 mins ago
excellent mosvy thanks mate
– conanDrum
34 mins 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%2f524793%2fis-it-possible-for-a-function-to-distinguish-if-it-is-run-like-this%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
proc is not a separate process in your example. It's just a function, run in the same process as the main shell.
The $FUNCNAME array gives it access to its backtrace:
foo(){ bar; }
bar(){ baz; }
baz(){ proc; }
proc(){ echo "${FUNCNAME[@]}"; }
$ foo
proc baz bar foo main
So yes, it can:
case ${FUNCNAME[1]} in runner) ...
If you experiment with it, you will see that running it in a subshell / subprocess doesn't break the backtrace or affect it in any way:
foo(){ (bar &) | cat; }
=> same output
true, I clarified my title. let me check what I can do with your info. thanks a bunch
– conanDrum
1 hour ago
I've added an example test and a note about functions, backtraces & subprocesses
– mosvy
58 mins ago
excellent mosvy thanks mate
– conanDrum
34 mins ago
add a comment |
proc is not a separate process in your example. It's just a function, run in the same process as the main shell.
The $FUNCNAME array gives it access to its backtrace:
foo(){ bar; }
bar(){ baz; }
baz(){ proc; }
proc(){ echo "${FUNCNAME[@]}"; }
$ foo
proc baz bar foo main
So yes, it can:
case ${FUNCNAME[1]} in runner) ...
If you experiment with it, you will see that running it in a subshell / subprocess doesn't break the backtrace or affect it in any way:
foo(){ (bar &) | cat; }
=> same output
true, I clarified my title. let me check what I can do with your info. thanks a bunch
– conanDrum
1 hour ago
I've added an example test and a note about functions, backtraces & subprocesses
– mosvy
58 mins ago
excellent mosvy thanks mate
– conanDrum
34 mins ago
add a comment |
proc is not a separate process in your example. It's just a function, run in the same process as the main shell.
The $FUNCNAME array gives it access to its backtrace:
foo(){ bar; }
bar(){ baz; }
baz(){ proc; }
proc(){ echo "${FUNCNAME[@]}"; }
$ foo
proc baz bar foo main
So yes, it can:
case ${FUNCNAME[1]} in runner) ...
If you experiment with it, you will see that running it in a subshell / subprocess doesn't break the backtrace or affect it in any way:
foo(){ (bar &) | cat; }
=> same output
proc is not a separate process in your example. It's just a function, run in the same process as the main shell.
The $FUNCNAME array gives it access to its backtrace:
foo(){ bar; }
bar(){ baz; }
baz(){ proc; }
proc(){ echo "${FUNCNAME[@]}"; }
$ foo
proc baz bar foo main
So yes, it can:
case ${FUNCNAME[1]} in runner) ...
If you experiment with it, you will see that running it in a subshell / subprocess doesn't break the backtrace or affect it in any way:
foo(){ (bar &) | cat; }
=> same output
edited 6 mins ago
Jeff Schaller♦
46.6k1167152
46.6k1167152
answered 1 hour ago
mosvymosvy
13.6k21546
13.6k21546
true, I clarified my title. let me check what I can do with your info. thanks a bunch
– conanDrum
1 hour ago
I've added an example test and a note about functions, backtraces & subprocesses
– mosvy
58 mins ago
excellent mosvy thanks mate
– conanDrum
34 mins ago
add a comment |
true, I clarified my title. let me check what I can do with your info. thanks a bunch
– conanDrum
1 hour ago
I've added an example test and a note about functions, backtraces & subprocesses
– mosvy
58 mins ago
excellent mosvy thanks mate
– conanDrum
34 mins ago
true, I clarified my title. let me check what I can do with your info. thanks a bunch
– conanDrum
1 hour ago
true, I clarified my title. let me check what I can do with your info. thanks a bunch
– conanDrum
1 hour ago
I've added an example test and a note about functions, backtraces & subprocesses
– mosvy
58 mins ago
I've added an example test and a note about functions, backtraces & subprocesses
– mosvy
58 mins ago
excellent mosvy thanks mate
– conanDrum
34 mins ago
excellent mosvy thanks mate
– conanDrum
34 mins 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.
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%2f524793%2fis-it-possible-for-a-function-to-distinguish-if-it-is-run-like-this%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