Giter VIP home page Giter VIP logo

Comments (2)

theclapp avatar theclapp commented on August 18, 2024

For the unaware (such as myself): The ${parameter@operator} is not in my local bash man page, I had to go looking for it. It came out in bash 4.4, circa late 2015. See https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html and search for ${parameter@operator}.

The @Q operator:

The expansion is a string that is the value of parameter quoted in a format that can be reused as input.

There are 9 other operators defined in the GNU Bash documentation. This package handles only @Q and @E, everything else panics. See

sh/expand/param.go

Lines 315 to 337 in 793d364

case syntax.OtherParamOps:
switch arg {
case "Q":
str, err = syntax.Quote(str, syntax.LangBash)
if err != nil {
// Is this even possible? If a user runs into this panic,
// it's most likely a bug we need to fix.
panic(err)
}
case "E":
tail := str
var rns []rune
for tail != "" {
var rn rune
rn, _, tail, _ = strconv.UnquoteChar(tail, 0)
rns = append(rns, rn)
}
str = string(rns)
case "P", "A", "a":
panic(fmt.Sprintf("unhandled @%s param expansion", arg))
default:
panic(fmt.Sprintf("unexpected @%s param expansion", arg))
}
.

Edit: And, obviously, it doesn't work for arrays, regardless.

from sh.

PigeonF avatar PigeonF commented on August 18, 2024

Ah, it seems you are right about only Q and E being supported. I remember trying @K as well, but it seems it did not error because I tried it for arrays. The following "succeeds" in the sense that it does not error, but the output is still wrong (which makes sense if expansion operators are just ignored for arrays)

$ gosh -c 'var=("some" "with space"); echo "${var[@]@K}"'
some with space

from sh.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.