Delete file content by asking user Yes/No...

I have following script to ping multiple ips but i want to delete ip.csv file content after running script .....but before deleting content i have ask user yes/No prompt depend on user input Yes/no ip.csv content will delete..

#!/bin/bash

for enodeb in `cat /tmp/ip.csv`
do
ping -c 2 $enodeb 1> /dev/null
if [ $? -eq 0 ]
then
echo -e "$enodeb     PASS" >> /tmp/list.csv
else
echo -e "$enodeb     FAILED" >> /tmp/list.csv
fi
      done
cat /tmp/list.csv

i use this it work but giving me error on "$ >ip.csv ;" line...

read -p "You want to clear ip.csv file ip's press(y/n)?" CONT
if [ "$CONT" == "y" ]; then
       $ >ip.csv ;  #giving eror on this line
  echo " ip.csv file is empty now ";
else
  echo "OK bye";
fi

PLease help me......

The $ is not a command :wink:

Change it to:

echo "" > ip.csv

hth

1 Like

Thanks...

> ip.csv would suffice, I think. This would not delete the file but render it empty.

1 Like