devbox icon indicating copy to clipboard operation
devbox copied to clipboard

[Bug]: Error running devbox shell in environment with exported Bash function

Open apgrucza opened this issue 2 years ago • 8 comments

Current Behavior (bug) To reproduce, run these commands:

foo() { echo foo; }
export -f foo
devbox shell

This error appears:

bash: export: `BASH_FUNC_foo%%=() {  echo foo}': not a valid identifier

Despite the error, the foo function is still available in the shell.

Expected Behavior (fix) The error should not appear.

Additional context My devbox version -v:

Version:     0.4.9
Platform:    linux_amd64
Commit:      b03f0d26da3df4318f2a8d70c0531c0c77d0d33c
Commit Time: 2023-05-02T23:26:52Z
Go Version:  go1.20.3
Launcher:    0.2.0

apgrucza avatar May 11 '23 08:05 apgrucza

same here any work around?

v3ss0n avatar Feb 17 '24 10:02 v3ss0n

Apparently, since the exported functions are available inside the devbox environment, the workaround is just to ignore the error.

I'ld still love it for the error not to appear, though, as I wasted quite a bit of time trying to figure out what was wrong with my env.

albx79 avatar Feb 24 '24 08:02 albx79

@albx79 , same thing, I spent about a few hours trying to figure out what went wrong

$ devbox shell
✓ Computed the Devbox environment.
Starting a devbox shell...
/tmp/devbox504213459/.zshrc:export:12: not valid in this context: BASH_FUNC_ml%

For some reason devbox take working function from my env

ml()
{
  eval "$($LMOD_DIR/ml_cmd "$@")"
}

and create this

export BASH_FUNC_ml%%="() {  eval \"\$(\$LMOD_DIR/ml_cmd \"\$@\")\"\
}";

Debug info

$ cat  /tmp/devbox504213459/.zshrc | grep BASH_FUNC_ml%% -B 1 -A 1
export BASH_ENV="/usr/share/lmod/lmod/init/bash";
export BASH_FUNC_ml%%="() {  eval \"\$(\$LMOD_DIR/ml_cmd \"\$@\")\"\
}";

$ zsh --version
zsh 5.9 (x86_64-redhat-linux-gnu)

$ cat /etc/os-release
NAME="Fedora Linux"
VERSION="38 (Workstation Edition)"

$ devbox version
0.10.1

Akiyamka avatar Mar 21 '24 11:03 Akiyamka

Look like it broke init_hook, it not running anymore

Akiyamka avatar Mar 24 '24 17:03 Akiyamka

plugins (corepack in my case) fails to execute they hooks too

Akiyamka avatar Mar 25 '24 09:03 Akiyamka

As I understand this code has this form intentionally, but I still can't figure out how to fix the error https://antonyt.com/blog/2020-03-27/exploiting-cgi-scripts-with-shellshock

Akiyamka avatar Mar 25 '24 09:03 Akiyamka

When i run devbox shell, I get this,

bash: export: `BASH_FUNC_which%%=() {  ( alias; eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot $@}': not a valid identifier

It doesn't seem to impact anything -- as other folks above have said, or is it really harmless? -- but it makes it hard for me to convince my team we should use this together.

Is there a flag or variable I can set in the dotenv.json file to bypass parsing or evaluating .bashrc or .bash_profile functions? Or is that misguided... that's part of devbox's charm I suppose when it all works smoothly?

staylorx avatar May 17 '24 16:05 staylorx

It doesn't seem to impact anything -- as other folks above have said, or is it really harmless?

I already mentioned that it breaks running init scripts. In other words, everything that's written in 

"shell": {  
    "init_hook": [  
        "echo 'This will never executed'"  
     ]  
}  

Not working because of crash

Akiyamka avatar Aug 08 '24 09:08 Akiyamka

For a Red Hat system, this causes problems because of which2.sh, found in /etc/profile.d. A workaround is to put unset which above the call to eval "$(devbox global shellenv)".

landtuna avatar Dec 16 '24 13:12 landtuna