简体   繁体   English

使用shell脚本执行shell命令

[英]executing shell command using shell script

I have shell command ./cherrypicker.sh input.txt which works fine in terminal. 我有shell命令./cherrypicker.sh input.txt ,在终端中可以正常工作。

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 所以我将所有这些都放在另一个shell文件alls.sh并试图像这样执行它

./alls.sh ./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? 正确的方法是什么?

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). cd到目录或使用完整路径(使用更适合该任务的路径)。

You might want to make sure that test.sh is actually executable by doing 您可能需要通过执行以下操作来确保test.sh实际上是可执行的

chmod 0700 /path/to/test.sh

And then run it without sudo. 然后在没有sudo的情况下运行它。

A note on sudo: it is not muckrake to get all your problems out of your way. 关于sudo的说明:摆脱所有麻烦并不是傻瓜。 ;) Think of it is rather a foil to punctually and elegantly make your point clear. ;)认为这是准时和优雅地阐明观点的障碍。 ;) ;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM