linux - 读取用户输入(应该是 linux 命令)并执行

标签 linux csh

我想写一个简单的 csh 脚本,循环遍历网络中的所有计算机并执行在命令行输入的命令

echo -n "Please enter command you would like executed on all computers > \n " set command = "$<"

假设用户输入 ls | grep 的东西。我将如何在下一行中执行此命令?我试过 $command对于 echo "Hello World" 这样的输入效果很好.我收到 ls | 的以下错误grep 一些东西

ls: |: No such file or directory ls: grep: No such file or directory ls: something: No such file or directory

理想情况下,我希望在循环遍历网络中的每台计算机(我已经可以这样做)并执行之前在命令行中输入多个命令。例如说我想复制两个不同的文件

sudo cp ./bin/elastix /usr/bin; sudo cp ./lib/transformix /usr/lib

谢谢

最佳答案

loops through all computers in a network and executes a command that is input at the command line

你可能会使用 ssh,所以你会做类似的事情:

ssh $hostname "$command"

我不是 csh 用户,所以我的语法可能有误。对于当前的机器,您可以使用 eval shell 命令,它应该解释任何命令序列,而不仅仅是简单的命令。

关于linux - 读取用户输入(应该是 linux 命令)并执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15069211/

相关文章:

linux - 就BSS、DATA、TEXT段而言,a.out文件包含什么?

linux - 在 tcsh 中隐藏 stderr 和管道 stdout

linux - 开启 fanotify 时多线程打开文件挂起

linux - AM335x - 用于 linux 内核的 i2c 从机

linux - 如何从 Linux 上的文件夹同步最后修改的文件

linux - 在特定字母/符号后将文件 2 中的行插入文件 1

awk - if else 代码中的 csh awk 语法错误

bash - csh 中 "setenv"的范围与 bash 中的 "export"

syntax-error - 如何在不退出 shell 的情况下在特定条件下停止采购 (t)csh 脚本?

c - 后台进程与前台进程