如何在不同的shell中执行命令?
How to execute a command in a different shell?
我有一个 bash 脚本可以打开一个名为 salome shell 的 shell,它应该在 shell 中执行一个名为 as_run 的命令。问题是进入莎乐美shell后,直到我退出莎乐美shell,它才执行命令。这是我得到的代码:
#!/bin/bash
cd /opt/salome/appli_V2018.0.1_public
./salome shell
eval "as_run /home/students/gbroilo/Desktop/Script/Template_1_2/exportSalome"
我应该怎么做才能执行salome中的命令shell?
大多数 shell 实现了一种将命令作为参数传递的方法,例如
dash -c 'x=1 ; echo $x'
您需要查阅 shell 的手册,看看是否可行。
您也可以尝试将命令发送到 shell 的标准输入:
echo 'set x = 1 ; echo $x' | tcsh
在复杂命令的情况下,使用 HERE 文档可能更具可读性:
tcsh << 'TCSH'
set x = 1
echo $x
TCSH
可能这就是您想要的:
# call salome shell with commands in a specified script file
cd /opt/salome/appli_V2018.0.1_public
./salome shell <"/home/students/gbroilo/Desktop/Script/Template_1_2/exportSalome"
或者这可能是您想要的:
# pipe a command as_run... to salome shell
cd /opt/salome/appli_V2018.0.1_public
echo "as_run /home/students/gbroilo/Desktop/Script/Template_1_2/exportSalome" | ./salome shell
无论如何,你必须阅读关于莎乐美shell如何调用它的脚本的莎乐美指南。
我有一个 bash 脚本可以打开一个名为 salome shell 的 shell,它应该在 shell 中执行一个名为 as_run 的命令。问题是进入莎乐美shell后,直到我退出莎乐美shell,它才执行命令。这是我得到的代码:
#!/bin/bash
cd /opt/salome/appli_V2018.0.1_public
./salome shell
eval "as_run /home/students/gbroilo/Desktop/Script/Template_1_2/exportSalome"
我应该怎么做才能执行salome中的命令shell?
大多数 shell 实现了一种将命令作为参数传递的方法,例如
dash -c 'x=1 ; echo $x'
您需要查阅 shell 的手册,看看是否可行。
您也可以尝试将命令发送到 shell 的标准输入:
echo 'set x = 1 ; echo $x' | tcsh
在复杂命令的情况下,使用 HERE 文档可能更具可读性:
tcsh << 'TCSH'
set x = 1
echo $x
TCSH
可能这就是您想要的:
# call salome shell with commands in a specified script file
cd /opt/salome/appli_V2018.0.1_public
./salome shell <"/home/students/gbroilo/Desktop/Script/Template_1_2/exportSalome"
或者这可能是您想要的:
# pipe a command as_run... to salome shell
cd /opt/salome/appli_V2018.0.1_public
echo "as_run /home/students/gbroilo/Desktop/Script/Template_1_2/exportSalome" | ./salome shell
无论如何,你必须阅读关于莎乐美shell如何调用它的脚本的莎乐美指南。