我正在制作一个简单的bash编码我不知道如何实现这一点,这对你们来说可能很容易请帮忙。
我在file.sh上有一个简单的程序
#!/bin/bash
./program
这个./program是C程序的编译版本,我使用GCC我试图在bash脚本中使用它来执行这个程序几秒钟然后在x间隔时间之后终止并再次重启。
我希望你明白我的观点?
示例:运行file.sh 10秒钟,我将显示./program C程序的结果,然后在10秒后重新启动。
答案 0 :(得分:2)
如果我理解正确,答案是sleep
和timout
的组合:
while :; do
timout 10s ./program
# display some results
sleep 10
done
答案 1 :(得分:0)
您可以使用$ pip install --verbose ./foo
Processing ./foo
Running setup.py (path:/private/var/folders/4d/bt0_xfx56bjfmmt2bv3r5_qh0000gn/T/pip-ti0o0gtu-build/setup.py) egg_info for package from file:///Users/pradyunsg/.venvwrap/venvs/t
mp-c0ebb35987c76ad/foo
Running command python setup.py egg_info
running egg_info
creating pip-egg-info/foo.egg-info
writing pip-egg-info/foo.egg-info/PKG-INFO
writing dependency_links to pip-egg-info/foo.egg-info/dependency_links.txt
writing top-level names to pip-egg-info/foo.egg-info/top_level.txt
writing manifest file 'pip-egg-info/foo.egg-info/SOURCES.txt'
reading manifest file 'pip-egg-info/foo.egg-info/SOURCES.txt'
writing manifest file 'pip-egg-info/foo.egg-info/SOURCES.txt'
Source in /private/var/folders/4d/bt0_xfx56bjfmmt2bv3r5_qh0000gn/T/pip-ti0o0gtu-build has version 0.0.0, which satisfies requirement foo==0.0.0 from file:///Users/pradyunsg/.ve
nvwrap/venvs/tmp-c0ebb35987c76ad/foo
Could not parse version from link: file:///Users/pradyunsg/.venvwrap/venvs/tmp-c0ebb35987c76ad/foo
Installing collected packages: foo
Running setup.py install for foo ... Running command /Users/pradyunsg/.venvwrap/venvs/tmp-c0ebb35987c76ad/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/privat
e/var/folders/4d/bt0_xfx56bjfmmt2bv3r5_qh0000gn/T/pip-ti0o0gtu-build/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(comp
ile(code, __file__, 'exec'))" install --record /var/folders/4d/bt0_xfx56bjfmmt2bv3r5_qh0000gn/T/pip-cetn8xa9-record/install-record.txt --single-version-externally-managed --compi
le --install-headers /Users/pradyunsg/.venvwrap/venvs/tmp-c0ebb35987c76ad/bin/../include/site/python3.6/foo
running install
Call install.run(self) works!
running build
running install_egg_info
running egg_info
creating foo.egg-info
writing foo.egg-info/PKG-INFO
writing dependency_links to foo.egg-info/dependency_links.txt
writing top-level names to foo.egg-info/top_level.txt
writing manifest file 'foo.egg-info/SOURCES.txt'
reading manifest file 'foo.egg-info/SOURCES.txt'
writing manifest file 'foo.egg-info/SOURCES.txt'
Copying foo.egg-info to /Users/pradyunsg/.venvwrap/venvs/tmp-c0ebb35987c76ad/lib/python3.6/site-packages/foo-0.0.0-py3.6.egg-info
running install_scripts
writing list of installed files to '/var/folders/4d/bt0_xfx56bjfmmt2bv3r5_qh0000gn/T/pip-cetn8xa9-record/install-record.txt'
done
Removing source in /private/var/folders/4d/bt0_xfx56bjfmmt2bv3r5_qh0000gn/T/pip-ti0o0gtu-build
Successfully installed foo-0.0.0
Cleaning up...
命令。例如:sleep
其中n是您希望命令进入休眠状态的时间。如果你想要,可以将它放在exec ./program && sleep n
脚本中的while循环中并连续运行。
要连续运行,直到您关闭终端:
sh