简体   繁体   English

如何重新运行脚本?

[英]How do I rerun a script?

I have a script that will check if a record exist and if it does then it will exit. 我有一个脚本,它将检查记录是否存在,如果存在,它将退出。 Now I am trying to find out how to re-run the script if record exist: 现在,我试图找出如果记录存在则如何重新运行脚本:

#!/bin/bash

echo Please enter hostname?
read hostname
echo
grep -q $hostname /home/user/ps/database
if [ $? -eq 0 ]
then
  echo Record exist
  echo
fi

Now I want to re-run the script if record exist. 现在,如果记录存在,我想重新运行脚本。 Please help 请帮忙

You just need a simple loop: 您只需要一个简单的循环:

#!/bin/bash

while :; do
  echo Please enter hostname?
  read hostname
  echo

  if grep -q $hostname /home/user/ps/database
  then
    echo Record exist
    echo
  else
    break
  fi
done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM