Variable equal to zero Linux 2.6.32-300.39.2.el


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Variable equal to zero Linux 2.6.32-300.39.2.el
# 1  
Old 11-25-2015
Variable equal to zero Linux 2.6.32-300.39.2.el

Code:
friends

as I can query for a variable that is zero, from a shell ??

# 2  
Old 11-25-2015
bash (and other bourne compatible shells): if [ -z $var ]; then ...; fi
This User Gave Thanks to RudiC For This Post:
# 3  
Old 11-25-2015
To test is a variable is zero:

Code:
if [ $var -eq 0 ]; then ....

or, using a string comparison
Code:
if [ "$var" = 0 ]; then ....

To test if a variable contains an empty string (""), you can use RudiC's suggestion...
This User Gave Thanks to Scrutinizer For This Post:
# 4  
Old 11-25-2015
Quote:
Originally Posted by Scrutinizer
To test is a variable is zero:

Code:
if [ $var -eq 0 ]; then ....

or, using a string comparison
Code:
if [ "$var" = 0 ]; then ....

To test if a variable contains an empty string (""), you can use RudiC's suggestion...

thank you !!!!
Use this option without problem


Code:
if [ $var -eq 0 ]; then ....

Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Linux

Linux command to find and replace occurance of more than two equal sign with "==" from XML file.

Please help me, wasted hrs:wall:, to find this soulution:- I need a command that will work on file (xml) and replace multiple occurrence (more than 2 times) Examples 1. '===' 2. '====' 3. '=======' should be replaced by just '==' Note :- single character should be replaced. (=... (13 Replies)
Discussion started by: RedRocks!!
13 Replies

2. Shell Programming and Scripting

weird equal variable issue

I run this #!/bin/bash cron=$(ps aux | grep crond | grep -v grep | grep -o crond| uniq) echo "cron :$cron:" if ; then echo "OK: crond service running fine on `hostname`" exit 2 else echo "CRITICAL: crond service not running on `hostname`" exit 0... (2 Replies)
Discussion started by: anil510
2 Replies

3. Shell Programming and Scripting

If not equal to then loop

How do I go about amending this simple script that prompts for a yes/no response so that if neither Y or N are entered it will loop back back to the original prompt #!/bin/ksh echo "Enter yes of no" read answer if then echo "You selected yes" elif then echo "You selected no" elif... (5 Replies)
Discussion started by: gmears
5 Replies

4. Shell Programming and Scripting

while [ $x -ge 50 ] + and equal to zero ; then

while + and equal to zero ; then what to punt instead of phrase and equal to zero. it's bash thank you in advance (1 Reply)
Discussion started by: losh
1 Replies

5. Linux

Installation of Linux in 300 MHz with 128 MB ram

Hi I am very new to Linux, but very keen to learn it. I am having a desktop of 300 MHz with 128 MB RAM and 30 GB hard drive with Windows XP. My first question is - Is there any version/flavour of Linux available that can be installed on above system especially Fedora with less compromise... (6 Replies)
Discussion started by: sanjay1979
6 Replies

6. UNIX for Dummies Questions & Answers

Making a variable equal a pattern

Hi, I would like to assign a pattern to a variable eg test8* or abc etc The problem I have is that when I assign the pattern to the variable, if any files within the current directory match the pattern then the variable will be evaluated to equal the filenames rather than the literal pattern.... (3 Replies)
Discussion started by: Bab00shka
3 Replies
Login or Register to Ask a Question