Skip to content

Allow use of FD higher than 9#247

Open
Saruspete wants to merge 1 commit intoshellspec:masterfrom
Saruspete:allow_fds_10
Open

Allow use of FD higher than 9#247
Saruspete wants to merge 1 commit intoshellspec:masterfrom
Saruspete:allow_fds_10

Conversation

@Saruspete
Copy link

@Saruspete Saruspete commented Sep 25, 2021

Hello,

I'm using fds 98/99 to be fairly high and not disturb scripts using my library.
When doing tests with:

UseFD 98
It "Emits a warning if an element is invalid"
    When call ammString::ExpandIntegerList "7-10,11,12,a-f,14-16"
    The fd 98 should include "is not an integer"
    The output should eq "7 8 9 10 11 12 14 15 16 "
End

It gave me errors:

Examples:
  1) string.lib: pattern matching: ammString::Contains returns success if a simple string is contained in another
     1.1) ERROR: UseFD: Invalid file descriptor: 98

I fixed it with a wildcard after the number to avoid ugly repetition of [0-9]|[0-9][0-9]| ... as we can have more than 20 numbers (max_files is an unsigned long in struct files_stat_struct of file linux/include/uapi/linux/fs.h )

Maybe you'll want to use an helper like "isInt" which is something like [[ -n "${1//[0-9]/}" ]] but I'm not sure on how you'll want it used.

Just to know, is a new release planned soon ?

Thanks a lot !
Adrien

@Saruspete Saruspete mentioned this pull request Nov 14, 2021
@sideeffect42
Copy link

POSIX only requires file descriptors 0-9 to be available (cf. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_07).

Also, [0-9]* in a glob has a different meaning to the same regular expression.
9foo also matches the glob, while the empty string does not match the glob, but matches the regular expression.

Maybe using arithmetic expansions (e.g. $(($2))) is a better idea, but needs special treatment for the integer 0, because all non integers will be expanded to 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants