The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Use ftp command in shell script infyanurag Shell Programming and Scripting 3 02-05-2008 08:06 AM
how to use cd command in shell script LAKSHMI NARAYAN Shell Programming and Scripting 3 09-09-2007 07:04 AM
Using the Esc key to complete command line typing jxh461 UNIX for Dummies Questions & Answers 1 06-05-2007 07:04 PM
vi command in shell script bryan UNIX for Dummies Questions & Answers 2 05-23-2006 08:51 PM
Shell script command dipanrc Shell Programming and Scripting 7 11-29-2005 11:15 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-28-2006
Draculla Draculla is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 3
Question Different in typing command and using shell script

Wondering why belows code works fine if i type in the command prompt but it seems not executed when i code them in a file with additional if-then-else statement.


Code:
#!/bin/sh

. $HOME/.profile

pid=`ps -ef | grep -w XELstnr | grep -v grep | awk {'print $2'}`

if [ $pid !='' ]
then
  echo "Stopping XELstnr....."
  kill -9 $pid
  echo "XELstnr stopped."
else
  echo "XELstnr is not running."

fi

exit


Please advise. Thanks.

Last edited by vino; 07-28-2006 at 05:14 AM.. Reason: Introduced code tags.
  #2 (permalink)  
Old 07-28-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
The if-else construct should be


Code:
if [ ! -z $pid ]

rather than


Code:
if [ $pid != ' ' ]

  #3 (permalink)  
Old 07-28-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,433
Vino, $pid must be between quotes :

Code:
if [ ! -z "$pid" ]

or

Code:
if [ -n "$pid" ]

Jean-Pierre.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:22 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0