Skip to content
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

Getting "line 33: `@out': not a valid identifier" #11

Open
guoyiz23 opened this issue Jul 16, 2023 · 8 comments
Open

Getting "line 33: `@out': not a valid identifier" #11

guoyiz23 opened this issue Jul 16, 2023 · 8 comments

Comments

@guoyiz23
Copy link
Contributor

I am running Git Bash (version 4.4) in Windows. source bach.sh within the shell works fine, sometimes it gives

bash: BACH_OS_NAME: readonly variable

However, when try to source this file within a .sh file, I get

bach.sh: line 33: `@out': not a valid identifier

How to resolve this? Thank you!

As an FYI, uname on my OS gives MINGW64_NT-10.0-22621.

Given that I would much interested in using this bash testing framework, I would also be willing to assist in the process of testing it on Windows (assuming it hasn't already been done to some extent). 也可以用中文跟我私下沟通。

@guoyiz23
Copy link
Contributor Author

guoyiz23 commented Jul 17, 2023

Now getting this:

$ source bach.sh
$ declare i=2
$ @assert-equals 4 "$((i*2))"
bash: 7: Bad file descriptor
1..0
# -----
# All tests: 0, failed: 0, skipped: 0

I hope to understand the code in this bach.sh over time. It uses some more advanced bash features some of which I have never even seen.

It is the first time I saw the likes of

function @out() {
    if [[ "${1:-}" == "-" || ! -t 0 ]]; then
        [[ "${1:-}" == "-" ]] && shift
        while IFS=$'\n' read -r line; do
            builtin printf "%s\n" "${*}$line"
        done
    elif [[ "$#" -gt 0 ]]; then
        builtin printf "%s\n" "$*"
    else
        builtin printf "\n"
    fi
} 8>/dev/null

I infer that this is associating file descriptor 8 to the output of the function and redirecting it to null. I am not sure why exactly you used file descriptors 7 and 8. Do they refer to anything specific?

@guoyiz23
Copy link
Contributor Author

After seeing for the first time the likes of

exec 3<> /tmp/foo # open fd 3.
echo a >&3 # write to it
exec 3>&- # close fd 3.

I am now well aware that you are opening file descriptors 7 and 8. And "bad file descriptor" seems to refer to usage of one which is not open. I am looking more at the code. Optimistically, I will eventually figure out what is going on. Of course, your response would also be much preferred.

@chaifeng
Copy link
Collaborator

chaifeng commented Aug 2, 2023

I am running Git Bash (version 4.4) in Windows. source bach.sh within the shell works fine, sometimes it gives

bash: BACH_OS_NAME: readonly variable

However, when try to source this file within a .sh file, I get

bach.sh: line 33: `@out': not a valid identifier

How to resolve this? Thank you!

As an FYI, uname on my OS gives MINGW64_NT-10.0-22621.

Given that I would much interested in using this bash testing framework, I would also be willing to assist in the process of testing it on Windows (assuming it hasn't already been done to some extent). 也可以用中文跟我私下沟通。

Sorry for my delayed replay, I've been quite busy recently.

I'm not sure what the reason is. I've met a problem before where the bash executed in MinGW was WSL's. Can you send me more details?

You can send me your wechat account id to my email (you can find it on my profile page) if you want ^_^

@chaifeng
Copy link
Collaborator

chaifeng commented Aug 2, 2023

Now getting this:

$ source bach.sh
$ declare i=2
$ @assert-equals 4 "$((i*2))"
bash: 7: Bad file descriptor
1..0
# -----
# All tests: 0, failed: 0, skipped: 0

I hope to understand the code in this bach.sh over time. It uses some more advanced bash features some of which I have never even seen.

It is the first time I saw the likes of

function @out() {
    if [[ "${1:-}" == "-" || ! -t 0 ]]; then
        [[ "${1:-}" == "-" ]] && shift
        while IFS=$'\n' read -r line; do
            builtin printf "%s\n" "${*}$line"
        done
    elif [[ "$#" -gt 0 ]]; then
        builtin printf "%s\n" "$*"
    else
        builtin printf "\n"
    fi
} 8>/dev/null

I infer that this is associating file descriptor 8 to the output of the function and redirecting it to null. I am not sure why exactly you used file descriptors 7 and 8. Do they refer to anything specific?

The pronunciation of the word "debug" is very simillar to Chinese pinyin "Di Ba Ge", so I choose the number "8" as the fd for debug output. Haha ;-P

@guoyiz23
Copy link
Contributor Author

guoyiz23 commented Sep 2, 2023

Can you respond to me via email? I just sent you bash code I wrote and use for searching files, which I hope to test more systematically with your bach. Thank you!

@blacktav
Copy link

blacktav commented Sep 8, 2023

@chaifeng

I am also got the error on ArchLinux but it turned out that my script was calling sh rather than bash

[drew@blacktav tests]$ cat base-testish.sh 
#!/bin/sh

source ./bach.sh

Press any key to continue...

[drew@blacktav tests]$ ./base-testish.sh
./bach.sh: line 33: `@out': not a valid identifier

So make sure you are actually running bash

@chaifeng
Copy link
Collaborator

chaifeng commented Sep 9, 2023

Hi @blacktav

Thank you! You're right!

@guoyiz23 sent me his script last week, I found it used /bin/sh, not /bin/bash. Also, there was another problem with the newline characters in the files, which needs special attention on Windows.

@qneill-sifive
Copy link

Perhaps '@Bach' should throw an error if executed in a non-bash shell?

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

No branches or pull requests

4 participants