X Tutup
The Wayback Machine - https://web.archive.org/web/20201123155723/https://github.com/shelljs/shelljs/issues/1002
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

sh: 0: Can't open ./simple-script.sh #1002

Open
shahmir811 opened this issue Aug 10, 2020 · 3 comments
Open

sh: 0: Can't open ./simple-script.sh #1002

shahmir811 opened this issue Aug 10, 2020 · 3 comments

Comments

@shahmir811
Copy link

@shahmir811 shahmir811 commented Aug 10, 2020

Hello!
I am using Node version: 10.19.0 and ShellJs version: ^0.8.4 with ubuntu 20.04

I am trying to execute following but it is giving an error (sh: 0: Can't open ./simple-script.sh):

const shell = require('shelljs');

const createAgent = (req, res, next) => {
	let output = 'Testing bash script';
	shell.exec('sh ./simple-script.sh');

	res.status(200).json({
		message: 'Agent created successfully',
		output,
	});
};

module.exports = {
	createAgent,
};

Script includes following lines:

#!/bin/bash

echo "Hello friends"

Need help to execute bash script with shelljs.

@nfischer
Copy link
Member

@nfischer nfischer commented Aug 11, 2020

Did you grant simple-script.sh executable permission?

chmod +x simple-script.sh

Or, your shelljs script can do this for you:

shell.chmod('+x', 'simple-script.sh');
shell.exec('sh ./simple-script.sh');
@shahmir811
Copy link
Author

@shahmir811 shahmir811 commented Aug 12, 2020

Thanks @nfischer for your reply. But I have already given execute rights to the file by executing following command:
chmod +x simple-script.sh

But nothing changed. I am still getting error.
sh: 0: Can't open ./simple-script.sh

@nfischer
Copy link
Member

@nfischer nfischer commented Aug 13, 2020

Did you double check you're in the right working directory before calling shell.exec()?

console.log(`The current working directory is ${shell.pwd()}`);
console.log(`Can shelljs see the file? ${shell.test('-f', 'simple-script.sh')}`);

If that's the problem, then you can fix this by calling shell.cd('path/to/correct/directory') before shell.exec().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.
X Tutup