-
Notifications
You must be signed in to change notification settings - Fork 86
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
[Feature] Loop files/directories (glob) #463
Comments
Nevermind |
i think that this |
Also, wrapping |
Okay, I see that the sample Amber script in Mte90's original post relies on
You can list files with spaces by escaping the whitespace in the glob:
However, this does not work when you pass the glob via a local variable, as we would in the transpiled Bash:
The only advice I've been able to find online is to "quote your variables", but this doesn't work with globs either:
I also tried using
By the way, there's another reason to use plain globs rather than wrapping
However, this does not fix the problem described above:
Anyone have any suggestions? |
I found this snippet working
I believe that this works because single quotes preserve the slash... But yeah... we wanted to store glob directly in a variable, or is this good enough? |
Ah, the one permutation I didn't try. Thanks! Will try to call that from an Amber script. |
|
This works:
|
@b1ek you suggested using The one thing |
I was thinking if we should introduce So the solution to this issue is to introduce the |
I don't like the actual proposal. Using I want to remember that the project is in alpha stage and the stdlib can be changed any time, so use https://www.gnu.org/software/findutils/ If we start to reimplement everything in pure bash in alpha stage we are becaming very complicate, without the real needs. |
@Mte90 |
There is a variable passed to the string that is the loop with an I don't think that is the case to expose the project to an eval for something that we can handle with |
|
I think that it needs to be a builtin so that we don't make double loop. We need to detect via syntax that a programmer wants to iterate over files and generate a native loop over given glob. Something like this:
Will transpile to something like this: for file in "*.txt"; do
echo file;
done; We can think of some syntax over the glob, but I think that string in the iterator position can be good enough signal to tell that we mean path with wildcards |
@KrosFire then the string should behave like glob in for loop. Like:
Then if
We'd get with the same loop:
|
Ok, on consideration I agree that using
Back to the drawing board then. I'll see what I can do about @KrosFire's suggestion above. |
@b1ek wrote:
For the record, the reason I had to use |
However, I would suggest not just using @KrosFire's syntax directly. I think it would be better to do:
Because at some point I would like to implement line by line reading with similar syntax like this:
|
Right now to loop files in Amber:
Requires stdlib for a single function.
Maybe we can do a dedicated builtin or a new stdlib function?
Something like:
In this way we can have also wildcard. Maybe is just a wrapper around
ls
like I already did in Amber?file_exist
it is needed as return also.
and..
so maybe we can clean up also that so the developer can do just:The text was updated successfully, but these errors were encountered: