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

Frum init detects wrong shell inside shell scripts #119

Open
depp opened this issue Apr 8, 2022 · 2 comments
Open

Frum init detects wrong shell inside shell scripts #119

depp opened this issue Apr 8, 2022 · 2 comments

Comments

@depp
Copy link

depp commented Apr 8, 2022

I’m not sure what the exact cause is here.

Here is test.sh, which is executable:

#!/bin/sh
eval "$(frum init)"

If this script is run from zsh, the shell is detected as zsh, even though this command is running from a dash process.

$ ./test.sh
./test.sh: 6: eval: autoload: not found
./test.sh: 11: eval: add-zsh-hook: not found

I can run it from Bash, however:

$ bash
$ ./test.sh

At first I thought this was because the script was running inside dash, which is not handled in the shell detector. However, it seems that Frum simply doesn’t detect the shell when the shell is running a script:

#!/bin/bash
eval "$(frum init)"

This fails too, when invoked from zsh.

Thinking of a few ways my issue could be solved:

  • Autodetect shells when invoked from shell script
  • Allow shell to be specified as parameter to init (like frum init --shell=sh)
  • Provide a way to invoke commands using frum (like frum exec)
@depp
Copy link
Author

depp commented Apr 8, 2022

It looks like the cause is that if you’re running a shell script, the process name is the name of the shell script, not the name of the shell. At least on Linux. It is easy enough to circumvent this by creating a subshell.

So, here's a workaround:

eval "$(sh -c 'frum init')"

@dechimp
Copy link

dechimp commented Apr 15, 2022

I was trying to run ruby commands from a cron job script but ran into this same scenario. However the above workaround still produces the same not found output for me.

This is an awful workaround, but it seems to get the job done:

ruby="/tmp/$(ls -t /tmp/ | grep frum_ | head -n 1)/bin/ruby"

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

2 participants