Beginner Bash Scripting Question

Hello,

I am new to Linux and studying to become a Unix System Admin. I am taking a course in which I was practicing creating a bash script to ping a particular IP address. The script can be found below:

#/bin/bash

echo "Enter the IP address"
read ip

if [ ! -z $ip ]
then
	ping -c 1 $ip

	if [ $? -eq 0 ] ; then
		echo "Machine is giving ping signal successfully"
	else
		echo "Machine is not giving ping signal unsuccessfully"

	fi

else
	echo "IP address is empty"

fi
  • My question is what does the ! -z do and what is it called? Is it a string operator? I tried Google but to no avail. Any help would be much appreciated. Thanks in advance.

Read the manpage for test .

man test
1 Like

Thank you! I was able to figure out after reading the man page for test

In the future, do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.