简体   繁体   English

Bash命令按顺序运行

[英]Bash commands run in sequence

The problem: 问题:

Number of the commands must be executed consequently, written in one-line command: 因此,必须以单行命令编写的命令数量必须执行:

comamand1; command2; command3;

The very first command is 第一个命令是

 sw user_name; 

The problem is that no commands are executed after the sw user_name; 问题是在sw user_name之后没有执行任何命令 one. 一。 (the user gets changed though) (尽管用户已更改)

Any ideas about how i can execute the string of the commands described above? 关于如何执行上述命令字符串的任何想法? 在此处输入图片说明

PS 聚苯乙烯

bash-3.2$ sw
Sorry, user ehwe is not allowed to execute '/bin/su -' as root on server_name

Guess it explains what the sw is :) 猜猜它解释了sw是什么:)

PPS sw stands for /bin/su - PPS sw代表/ bin / su-

Hoping that you meant "su" and not "sw" . 希望您的意思是“ su”而不是“ sw”。 If you wanted to switch as some user and execute set of commands probably you can use -c option. 如果您想以某些用户身份切换并执行命令集,则可以使用-c选项。 you can try something like this su - chidori -c "date;ls;df" 您可以尝试类似su - chidori -c "date;ls;df"

It sounds to me like sw might be some sort of alias to su . 在我看来, sw可能是su某种别名。 You can check with alias sw . 您可以使用alias sw检查。 If this is the case, you could probably use chidori's answer, just replace su with sw . 如果是这种情况,您可能可以使用chidori的答案,只需将sw替换为su

You cannot change the user of a given process; 您不能更改给定进程的用户; you can only start a new process running as the new user. 您只能启动以新用户身份运行的新进程。 As such, sw is probably starting a new interactive shell. 因此, sw可能正在启动一个新的交互式shell。 When that shell exits, the sw command completes, and the next command in your sequence can complete. 当该shell退出时, sw命令完成,并且序列中的下一个命令可以完成。 For example: 例如:

$ sw user_name; echo "Second command executes"
$ echo hello
hello
$ exit
Second command executes

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

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