0

I have shell command ./cherrypicker.sh input.txt which works fine in terminal.

But I want to execute few more command before and after this command like

echo "some text" > input.txt
./cherrypicker.sh input.txt
result < input.txt.response
rm input.*

So I put all this in another shell file, alls.sh and tried to execute it like this

./alls.sh

which says

bash: ./test.sh: Permission denied

then

sudo ./alls.sh

which gives

sudo: ./test.sh: command not found

what is the correct way?

2
  • 1
    Where do you run test.sh ? Inside cherrypicker.sh ? Could you show how you do it? Commented Sep 18, 2014 at 9:40
  • You need to give us the content of alls.sh. Commented Sep 18, 2014 at 9:41

2 Answers 2

2

Add execution rights to the script:

chmod +x test.sh

The second problem is related to the path. cd to the directory or use the full path (use whichever is more appropriate for the task).

Sign up to request clarification or add additional context in comments.

6 Comments

That is a bad idea, since it would make the script executable for everyone, even nobody:nogroup. There is a reason for umask, as you surely know. u+x would be the much better solution.
@MarkusWMahlberg: There's usually nothing wrong with giving execute rights to everyone. Telll me, what's wrong with giving someone rights to execute a file? The access right restrictions for the input and output files are still in place. They won't be able to read/modify your files. I think you're trying to solve the problem on the wrong level. It's a nice share ecosystem, don't add restrictions, unless necessary.
Well, as I have learned it, there is something which is called the principle of least rights, applying to both users and files. Without knowing the previous settings of the file, a +x would simply make it executable for everybody. What if setuid bit was set? If it is a personal script, it should have according permissions. If it is to be made public, those permissions still can be adjusted. But an unconditional +x potentially has security implications without offering any benefit as per the question.
@MarkusWMahlberg: security and openness are two opposing forces. there are many cases where the former is a lot more important, and in those environments you're absolutely right. just be aware that the are other forces, and don't carve your rules in stone. the accepted answer with 0700 is just as bad, and doesn't explain what it is doing, either.
I'd suggest we discuss this here chat.stackoverflow.com/rooms/info/61480/…
|
2

You might want to make sure that test.sh is actually executable by doing

chmod 0700 /path/to/test.sh

And then run it without sudo.

A note on sudo: it is not muckrake to get all your problems out of your way. ;) Think of it is rather a foil to punctually and elegantly make your point clear. ;)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.