LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-19-2014, 09:43 PM   #1
byran cheung
Member
 
Registered: Sep 2013
Posts: 321

Rep: Reputation: Disabled
the meaning in the script


I find the below script but I am not understand the function of this script .

Would advise what is the mean of "x" , what is the use of "x" in comparsion ? thanks

chk_running()
{
if [ "x"${PID} != "x" ]; then
echo "PID: "${PID}

if ..

else
RUNNING="F"
fi
else
RUNNING="F"
fi
}
 
Old 06-20-2014, 01:12 AM   #2
rhoekstra
Member
 
Registered: Aug 2004
Location: The Netherlands
Distribution: RedHat 2, 3, 4, 5, Fedora, SuSE, Gentoo
Posts: 372

Rep: Reputation: 42
A weird way to determine whether variable PID is empty or not
 
Old 06-20-2014, 03:30 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,996

Rep: Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187
Not weird ... just old (like some of us)

[] is not as robust as the newer [[]] and hence it will throw an error if you test against an empty variable and no additional character.

Simple test is to take away the "x" from both sides and see what your 'if' does now
 
Old 06-20-2014, 03:49 AM   #4
rhoekstra
Member
 
Registered: Aug 2004
Location: The Netherlands
Distribution: RedHat 2, 3, 4, 5, Fedora, SuSE, Gentoo
Posts: 372

Rep: Reputation: 42
I must admit 'weird' doesn't cut it.. but also, I'm very BASH minded, not old enough for the korn or SH shell languages to know the implications to test this way.

within BASH you can use '-n' or '-z' to verify non-empty or 'zero-length' of a string, which you should surround by "" not to have an exception.

I'm quite confident that "$PID" != "" would have sufficed as well which makes more sense...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Explain me the meaning of this line in shell script antriksh Linux - Newbie 1 01-05-2013 12:44 PM
Whats the meaning of set -e inside the script jao_madn Programming 2 12-01-2011 01:46 PM
What is meaning about the regular expression pertaining to vim script? haochao Programming 2 03-25-2009 12:08 AM
Meaning of certain commands in script? SlowCoder Linux - General 2 10-12-2007 11:21 AM
'./file' meaning in python & shell script Chowroc Programming 7 12-30-2005 02:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration