Beginner Bash Scripting Question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Beginner Bash Scripting Question
# 1  
Old 08-22-2015
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:

Code:
#/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.
# 2  
Old 08-22-2015
Read the manpage for test.

Code:
man test

This User Gave Thanks to DukeNuke2 For This Post:
# 3  
Old 08-22-2015
Thank you! I was able to figure out after reading the man page for test
# 4  
Old 08-22-2015
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Total Noob BASH scripting question

Hello All, I have a file of ip addresses called activeips.txt What I'm trying to do is run a simple bash script that has a loop in it. The loop is a cat of the IP addresses in the file. The goal is to run 2 nmap commands to give me outputs where each address in the list has an OS... (11 Replies)
Discussion started by: Dirk_Pitt
11 Replies

2. UNIX for Beginners Questions & Answers

Beginner at bash scripting - need help with passing arguments

I at the moment, making a simple bash script, capable of setting up an workspace for me, so i don't have to do it manually.. Problem is though i can't seem to provide the bash script any argument, without running into my error checks, checking for input... Here is the code: #!/bin/bash... (7 Replies)
Discussion started by: kidi
7 Replies

3. Shell Programming and Scripting

Beginner - scripting help!

hi all, i am very new to linux and am trying to create a basic script. I would like the script to copy files from one directory into another, (e.g Script ~/my-documents/fileone ~/my-documents/filetwo) Once all files have been copied, i'd like another script to run automatically and rename... (12 Replies)
Discussion started by: highland
12 Replies

4. Shell Programming and Scripting

Bash scripting question

have a script that calls child scripts depending on conditions. All of the child scripts source in a common file that contains shared functions. At the moment each script has to source this file itself, is there a way for the master script to automagically source the file for them? For... (3 Replies)
Discussion started by: redman
3 Replies

5. OS X (Apple)

scripting beginner

hi i have been given the task of sorting some scripting issues , i first of all need to decifer the ones that are being used is there anybody can do this for me :rolleyes: (4 Replies)
Discussion started by: aguiness
4 Replies

6. Shell Programming and Scripting

[Bash] Beginner at scripting

Hi, I'm a beginner at shell scripting, just started scripting in bash a few days ago. I want to test if the command ls *.jpg returns exit code 2, and if yes I want to execute a new command ls *.jpeg, doing a test on it... and pretty much repeat the procedure. Is this correct? #!/bin/bash... (1 Reply)
Discussion started by: Utherr
1 Replies

7. Shell Programming and Scripting

Bash scripting, question about a variable

Hey, So I've run into a problem, due to my limited knowledge of Bash scripting. Basically I've got a long script and I want to understand it before I even try and edit it. As long as I don't understand the script, I will not bother editing it. Anyway, the following variable confuses me... (5 Replies)
Discussion started by: abciscool
5 Replies

8. Shell Programming and Scripting

Beginner bash scripting - a few problems

Hey Guys, I am creating a bash script on my freeBSD box, the script should basically ask the user to enter a username and domain. The script will take this information and basically append alot of information to config files so the user can receive email from that domain and create a web site at... (1 Reply)
Discussion started by: traxy
1 Replies

9. Shell Programming and Scripting

Bash scripting question re: newlines

I'm writing a bash script to search the contents of a postfix log. To keep the script's output readable (since multiple lines from the log file need to be echo'ed) I am setting the IFS variable to an empty string so that the line breaks in my grep results are preserved. I am storing the results... (4 Replies)
Discussion started by: retrovertigo
4 Replies
Login or Register to Ask a Question