Skip to content
This repository has been archived by the owner on Sep 23, 2021. It is now read-only.

Breaks with bash redirections #1

Closed
davej opened this issue Jun 28, 2015 · 10 comments
Closed

Breaks with bash redirections #1

davej opened this issue Jun 28, 2015 · 10 comments

Comments

@davej
Copy link

davej commented Jun 28, 2015

For example, the following bash will give a permissions fail:

sudo-prompt.exec("echo 'some text' > /Library/some-file.txt")

It's easily fixed by doing:

sudo-prompt.exec("bash -c \"echo 'some text' > /Library/some-file.txt\"")

Perhaps sudo-prompt should do this (bash -c) at the module level instead? String escaping may need a little bit of thought but should be ok.

@jorangreef
Copy link
Owner

The idea behind sudo-prompt is to prefix a command with "sudo" but show an os dialog if permissions would be necessary.

So, sudo-prompt at the moment would take your command above and run:

sudo echo 'some text' > /Library/some-file.txt

...but it would also take care of the os prompt along the way.

The issue at the moment if I understand correctly is that calling that command using sudo also fails:

 $ sudo echo 'some text' > /Library/some-file.txt
-bash: /Library/some-file.txt: Permission denied

The echo 'some text' is run using sudo, but the redirection to /Library is not.

The bash -c trick is a good idea. I am not sure how this would affect propagating command errors out of the bash shell. I will give it a try and see if we can make the changes.

@davej
Copy link
Author

davej commented Jul 1, 2015

Yup that's it.

After some basic testing, stdout and stderr both propagate up to the node callback exactly as expected.

If you like I can make a PR?

@jorangreef
Copy link
Owner

Thanks that would be great.

@jorangreef
Copy link
Owner

Does the exit code also propagate?

@davej
Copy link
Author

davej commented Jul 2, 2015

I presume so but I haven't tested that, I'll give it a test when I have a few spare minutes.

@davej
Copy link
Author

davej commented Jul 2, 2015

Just tried bash -c 'exit 0'; and it doesn't seem to propagate.

@davej
Copy link
Author

davej commented Jul 2, 2015

Did a bit more testing, this does propagate signals: exec bash -c 'exit 0'.

edit: typo.
second edit: Actually that seems to break stdout ughh.

@davej
Copy link
Author

davej commented Jul 2, 2015

The more I test this, perhaps it's best to leave it out of the lib, unless there's a straightforward way to do it. I'm not familiar enough with the intricacies of bash.

@jorangreef
Copy link
Owner

Thanks for trying, at least the bash -c is documented here for those that need to redirect sudo output.

@deiucanta
Copy link

Using -e flag on bash will exit immediately on error.

@davej Zero is the code for successful exists. If you want to "throw" an error you must exit with something different than zero.

http://unix.stackexchange.com/questions/15998/what-does-the-e-do-in-a-bash-shebang

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants