无限循环中的 Bash exec 不起作用 [英] Bash exec in infinite while loop doesn't work

查看:44
本文介绍了无限循环中的 Bash exec 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#!/bin/bash 
while :
do
    echo twerkin
    exec free -h > /ver/www/raspberry/load.txt
    exec /opt/vc/bin/vcgencmd measure_temp > /var/www/raspberry/heat.txt
done

这是我做的,我打算在我的网站上阅读它,但这不是问题.问题是它给了我这个错误:

This is what I made, I am going to read it on my website, but thats not the problem. The problem is that it gives me this error:

pi@raspberrypi ~ $ sh showinfo.sh
showinfo.sh: 7: showinfo.sh: Syntax error: "done" unexpected (expecting "do")

我正在使用 Raspbian (Debian Wheezy) 在我的 raspberry pi 上运行这个

I'm running this on my raspberry pi with Raspbian (Debian Wheezy)

推荐答案

您似乎不明白 exec 关键字的作用.它用 free 命令替换您当前的脚本(基本上,while 循环).

You don't seem to understand what the exec keyword does. It replaces your current script (basically, thewhile loop) with the free command.

要运行命令,只需指定它.

To run a command, simply specify it.

#!/bin/bash

while : ; do
    free -h
    /opt/vc/bin/vcgencmd measure_temp 
done

(我省略了重定向,因为您在每次迭代时都覆盖了旧结果.您真正想要什么?)

(I omitted the redirections because you were overwriting the old results on each iteration. What do you actually want?)

这篇关于无限循环中的 Bash exec 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆