Comments (6)
Thanks, I think this should be pretty easy, and I should be able to get it for the next release!
from oil.
Looking through code I've written recently, I've also seen the following uses of declare:
- 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 )
- Declaring a variable read-only and an array:
declare -ar foo=( b )
- 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.
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.
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.
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.
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)
- Consider using -> in 3 or 4 places to connote mutability/aliasing HOT 4
- `try` / `$_error` not compatible HOT 3
- Minimal YSH That's Pretty Stable (list of issues)
- Modules v2 - with namespaces HOT 3
- ysh-simple parsing / let command language and typed args compose HOT 23
- [YSH] --flag=u'\n' versus --flag u'\n' is a possible pitfall - first style could be disallowed HOT 19
- [YSH] setglobal d.key mutates local instead of global HOT 7
- [YSH] Document idiom for mutable default params (setvar param = param or default doesn't work with empty containers) HOT 23
- [osh] echo -E not implemented HOT 3
- spec/testdata/ysh-read-0.sh problem? HOT 10
- Interactive: command_not_found_handle (nix-shell) HOT 3
- `try eval` is inconsistent HOT 11
- Typed args and block arg can get confused HOT 8
- Parsing bug with comma after typed arg HOT 1
- setvar a = u'\0' => AssertionError HOT 1
- test/runtime-errors.sh pipefail bug
- traps in osh -c don't run when the final command is not a shell builtin HOT 3
- Brace expansion combined with tilde expansion should behave like bash and zsh, not mksh
- Parse (but don't execute) a limited amount of zsh syntax - the "ifdef" pattern
- Separate typed proc and plain proc (string args only) HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from oil.