-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat: implement $SHLVL
and $BASH_SUBSHELL
#251
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,37 @@ cases: | |
- name: "Piped subshell usage" | ||
stdin: | | ||
(echo hi) | wc -l | ||
|
||
- name: "SHLVL subshell" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like we need some tests to ensure that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @reubeno I thought about it and created a test using $SHELL but is points to nowhere inside the Oracle. Now, looking at it, I learned about
|
||
stdin: | | ||
initial="$SHLVL" | ||
function rec_subshell { | ||
if [ "$1" -ge "$2" ]; then | ||
exit | ||
else | ||
( | ||
test $initial -eq $SHLVL; echo $? | ||
rec_subshell $(($1 + 1)) $2 | ||
) | ||
fi | ||
} | ||
rec_subshell 1 10 | ||
|
||
|
||
- name: "BASH_SUBSHELL" | ||
stdin: | | ||
initial="$BASH_SUBSHELL" | ||
|
||
function rec_subshell { | ||
if [ "$1" -ge "$2" ]; then | ||
exit | ||
else | ||
( | ||
test $initial -ne $BASH_SUBSHELL; echo $? | ||
echo $BASH_SUBSHELL | ||
initial=$BASH_SUBSHELL | ||
rec_subshell $(($1 + 1)) $2 | ||
) | ||
fi | ||
} | ||
rec_subshell 1 10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shell.rs
is already, well, longer than I'd like. Could you turn this into apub(crate)
helper invariables.rs
or similar?For what it's worth, it seems more understandable to me to have the
default
value expressing the pre-increment default (i.e.,0
here).