简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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