GithubHelp home page GithubHelp logo

Comments (6)

andychu avatar andychu commented on July 24, 2024 1

Thanks, I think this should be pretty easy, and I should be able to get it for the next release!

from oil.

travisbhartwell avatar travisbhartwell commented on July 24, 2024

Looking through code I've written recently, I've also seen the following uses of declare:

  1. Declaring a variable as an array, with or without setting the value:
# filenames is an array
declare -a filenames
# foo is an array with one element, b
declare -a foo=( b )
  1. Declaring a variable read-only and an array:
declare -ar foo=( b )
  1. Declare a string as only upper case or only lower case:
declare -u upper_region_name="${region}"
declare -l lower_region_name="${region}"

Related, I've used local and readonly similarly:

function() {
    local src="$1"
    local -r read_only_src="$2"
}

# Read only file-level variable
readonly [email protected]

# Only set ENV_NAME if it isn't already
: "${ENV_NAME:='MyEnvironment'}"
# Make it read-only
readonly ENV_NAME

from oil.

andychu avatar andychu commented on July 24, 2024

Hi Travis, I'm starting to look at this now. Just curious what you use -u and -l for?

It shouldn't be hard to implement them. But I'm a little wary about checking extra flags on every assignment, since it could more or less be written:

$ foo=xyz
$ foo=${foo^^}
$ echo $foo
XYZ

Or is there a reason that -u and -l are preferable for your use case?

from oil.

travisbhartwell avatar travisbhartwell commented on July 24, 2024

No, no reason they are preferable. I didn't know about case modification as part of parameter expansion. I can't remember where I saw the flag. These are not variables that are set more than once, so making the variable always be upper or lower aren't requirements, I can use the parameter expansion versions instead.

from oil.

andychu avatar andychu commented on July 24, 2024

OK great thanks for letting me know! I landed these changes on the master branch. If you want to try it on your code, you can clone and make a "dev build", which should take 30 seconds if you have an Ubuntu machine:

https://github.com/oilshell/oil/wiki/Contributing

It's somewhat dependent on the environment, there are few dependencies.

Still aiming for a 0.4 release by the end of the month, maybe early next month. I've been working on trap as well.

from oil.

andychu avatar andychu commented on July 24, 2024

0.4.alpha1 release is here: http://www.oilshell.org/releases.html

I'm closing this for now -- please test and reopen if there are issues :)

from oil.

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.