bach-sh/bach

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

guoyiz23 opened this issue · 9 comments

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). 也可以用中文跟我私下沟通。

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?

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.

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 ^_^

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

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!

@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

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.