Skip to content

0o[777] is not working #9566

Closed
Closed

Description

@baehyunsol

Describe the bug

It's an octal number, 511 in decimal. 0o[7] and 0o[77] work fine, but for 0o[777], nushell says "executable was not found"

0o[7777], 0o[77777], ... do not work.

How to reproduce

Type 0o[777]

Expected behavior

Supposed to be interpreted as a octal number (in binary type), but the shell tries to find an executable named 0o[777].

Screenshots

No response

Configuration

key value
version 0.82.0
branch
commit_hash
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.70.0 (90c541806 2023-05-31)
rust_channel stable-x86_64-unknown-linux-gnu
cargo_version cargo 1.70.0 (ec8a8a0ca 2023-04-25)
build_time 2023-06-29 15:52:43 +09:00
build_rust_channel release
allocator standard
features default, sqlite, trash, which, zip
installed_plugins

Additional context

No response

Activity

  1. added
    status:needs-triage
    on Jun 30, 2023
  2. baehyunsol commented on Jun 30, 2023

    @baehyunsol
    ContributorAuthor

    I'll try further debugging this evening!

  3. sholderbach commented on Jun 30, 2023

    @sholderbach
    Member

    Oo[777] is not a valid octal literal as this would represent 9 and not 8 high bits. Apparently we don't surface an error message for that and thus we fall back to parsing this as a bare word and thus try to find the binary named like that.

  4. added
    A:parser
    A:error-unhelpful
    and removed
    status:needs-triage
    on Jun 30, 2023
  5. fdncred commented on Jun 30, 2023

    @fdncred
    Contributor

    I didn't even know that 0o[7] would work. I thought the syntax was just 0o777

  6. sophiajt commented on Jul 2, 2023

    @sophiajt
    Contributor

    @fdncred @sholderbach it's for binary data rather than an integer.

    This should just work as stated. I think there's a bug in the octal binary parser.

  7. sholderbach commented on Jul 2, 2023

    @sholderbach
    Member

    But what would be the meaning of 777? 1 377 or 7 077

  8. baehyunsol commented on Jul 2, 2023

    @baehyunsol
    ContributorAuthor

    It's just 777, it should be that 0o[777] == 0b[111 111 111] because 0o777 == 0b111_111_111. nushell left-pads incomplete bytes with zeros.

    [
      (0o777 == 0o111_111_111),  # true
      # (0o[777] == 0b[111 111 111]),  # error
    ]

    The above should be

    ╭───┬──────╮
    │ 0 │ true │
    │ 1 │ true │
    ╰───┴──────╯
    
  9. sholderbach commented on Jul 3, 2023

    @sholderbach
    Member

    You are both right @jntrnr and @baehyunsol. Was very byte brained late last night.

  10. removed
    A:error-unhelpful
    on Jul 3, 2023
  11. sholderbach commented on Sep 17, 2025

    @sholderbach
    Member

    Closing as this carrying behavior for octal encoded binary strings is likely more confusing.

    See #16678 (comment)

    I think while your reasoning here makes sense for the octal int literal 0o77777 etc. I am not sure if we should use this carry semantics for the binary/byte string literals:

    In a C string you would for example write:

    char str[] = "\377\377\377\0";

    with a readable Nushell equivalent:

    let str = 0o[377 377 377 000] # Note that you currently need to pass multiples of three for the octal coded byte string which makes the chunking consistent

    If you want to express the carrying single int semantics you have the 0o1234567 syntax available and can convert into binary.

    and #16678 (comment) for a limited alternative if you want to express this carry across byte boundaries for short (i64) strings of octal.

    For better erros we will have #16688

  12. added a commit that references this issue on Sep 17, 2025
    4062cbd
  13. added this to the v0.108.0 milestone on Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:parser

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions