-
-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Output of declare -p / declare / declare -f / trap -p / trap (ble.sh) #647
Comments
Yes I've seen this in other scripts too. Unfortunately it's not implemented, but I'll leave this issue open and see who else runs into it. |
Note: Oil is trying to discourage use of
|
Thank you very much for reviewing all the issues!
OK, for this point, I actually agree with you. One doesn't need The situation is special for ble.sh which needs to handle user inputs within the shell instance without slow operations like
Yes, but it's usually more handy and efficient to use
I'm sorry that I didn't explain the usage in details, but save/restore does not (necessarily) mean it's saved into some file and read from it. It's just saved into a shell variable and later read from that variable (as indicated by the original post There is also another usage of function fun {
do_something
eval -- "$(
some_command | {
do_something
declare -p resultA resultB resultC; } )"
use_results
} Digression: Use case of saving states in a shell variable in ble.shMaybe it is non-trivinal why ble.sh needs to do such things (saving states in a shell variable). The shell script language lacks the feature of object-oriented structures, so if one wants to handle some objects (which are composed of multiple member variables), some mechanism to carry and specify a set of variables. The script ble.sh uses several different ways to specify the set of variables depending on the usage and frequency of the switching of the object to be handled.
|
Use an imperative form to support arrays with unset elements. Addresses issue #647
Regarding ble.sh and #653, I also wonder if #704 to eval code in a subinterpreter would eliminate the need for That is, if there is an interpreter for ble.sh and one for the user, then we wouldn't have to save and restore state with But I understand that could be a big change to the codebase and maybe not worth it now. I point it out since ( |
Maybe it could partially eliminate the need for
The reason why I marked with a star is because there is no other way to achieve this. Actually, this is not so important for running the essential part of
Maybe you are talking about save/restore of functions without providing a string representation of the function body, but I just want to obtain a string representation of the function body.
|
OK great, thanks for clarifying the use cases. That helps. |
Oil does not print the definition of variables for
declare -p
. The script ble.sh usesdeclare -p
to save states of scalar variables and arrays (saved=$(declare -p foo bar)
) which will be later used to restore the states byeval
(eval -- "$saved"
). I believe this is the expected usage of Bashdeclare -p
(which is the reason that it prints the reusable form foreval
).Similarly Bash prints the definition of all the variables and functions with
declare
without arguments, but Oil does nothing for this.$ bin/osh -c 'a=1; declare' $
In Bash, the function definition can be obtained by
declare -f
. But Oil does not provide the function body but only the function name. The script ble.sh usesdeclare -f
to save/restore the functions or dynamically patch the behavior of existing functions. (If you are interested, maybe you can have a look at meta functionsble/function#push
,ble/function#pop
, andble/function#advice
in src/util.sh of the ble.sh source for save, restore, and patching, respectively).Is there any other way in Oil to obtain the body of existing shell functions? I tried
trap
type
but it neither output the body.Bash builtin
trap
also produces reusable form which can be used for save and restore of trap states. However, Oil produces not reusable form of outputs.In Bash,
trap
without arguments prints the current set of the registered traps in the same way astrap -p
. But Oil produces an error.The text was updated successfully, but these errors were encountered: