简体   繁体   English

在Shell脚本中调用多个命令

[英]Calling multiple commands in a shell script

This is my command.sh [After entering the command nothing happened][2]I want to automate the commands in putty so i have written the commands in a shell script and called it from a batch file 这是我的command.sh [输入命令后,什么都没发生] [2]我想自动执行腻子中的命令,所以我已将这些命令写在shell脚本中并从批处理文件中调用

echo -e "password" | sudo -S screen -ls  
pwd 
cd .. 

these are the commands in shell script, but the commands pwd , cd are not executing after sudo commands..... No commands are working under sudo commands 这些都是shell脚本的命令,但命令pwdcd后不执行sudo命令.....没有命令下工作sudo命令

That happens because you launch screen and the process never exits so the bash script cannot move forward to the pwd and cd commands 发生这种情况是因为您启动了屏幕,并且该过程永不退出,所以bash脚本无法前进到pwdcd命令。

As a workaround you may write down your commands into the shell script and execute it in screen using 作为一种解决方法,您可以将命令写下到shell脚本中,然后使用以下命令在屏幕上执行

screen -d -m bash ./script.sh

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

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