如何grep文件然后打印出来? Unix的

时间:2015-10-13 06:01:24

标签: bash unix

while true

do


if($update)
then
    who | awk {'print$1'} > first_user_list #store original user list
    update=false
fi

who | awk {'print$1'} > updated_user_list

(diff first_user_list updated_user_list) | cut -c 3- > in_out_list
inOutVar='cat in_out_list' #<----here's my problem

length_first=$(wc -l < updated_user_list)
length_update=$(wc -l < first_user_list)

if [[  "$length_first" -lt "$length_update" ]]; then
    echo -e "$inOutVar" " has logged out"
    update=true
elif [ "$length_first" -gt "$length_update" ]; then
    echo -e "$inOutVar" " has logged in" 
    update=true
else
    echo No user has logged in/out in the last 3 seconds
fi

sleep 3
done

如何打印出已注销的用户名&#34;已退出&#34; 例如。

&#34; johnsmith已退出&#34;

对unix来说很新,任何帮助或建议都会很棒,提前谢谢:)x

1 个答案:

答案 0 :(得分:1)

您的问题是您使用了引号而不是反引号。由于您将变量设置为等于命令,因此需要使用``或$():

public class MyWebViewClicker extends Activity implements OnTouchListener,     Handler.Callback {

private static final int CLICK_WEBVIEW = 1;
private static final int CLICK_URL = 2;

private final Handler handler = new Handler(this);

private WebView webView;
private WebViewClient webviewclient;
boolean donext=false;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.web_view);

webView = (WebView)findViewById(R.id.myweb);
webView.setOnTouchListener(this);

webviewclient = new WebViewClient(){ 
    @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { 
        handler.sendEmptyMessage(CLICK_URL);
        return false;
    } 
}; 

webView.setWebViewClient(webviewclient);
webView.setVerticalScrollBarEnabled(false);
webView.loadUrl("http://www.example.com");
}

@Override
public boolean onTouch(View v, MotionEvent event) {
if (v.getId() == R.id.myweb && event.getAction() == MotionEvent.ACTION_DOWN)  {
    handler.sendEmptyMessageDelayed(CLICK_WEBVIEW, 500);
}
return false;
}

@Override
public boolean handleMessage(Message msg) {
if (msg.what == CLICK_URL){
    Toast.makeText(this, "URL is clicked", Toast.LENGTH_SHORT).show();
    donext=true;
    return true;
}
if (msg.what == CLICK_WEBVIEW){
    if(donext==true)
    { 
      //do nothing
    }else{
    Toast.makeText(this, "WebView is clicked", Toast.LENGTH_SHORT).show();
     }
    return true;
}
return false;
}
}

这适用于我的系统。