A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Engineering
»
Linux / UNIX
Author
compare OS command with String value in Shell Script ?
kri shan
Ranch Hand
Joined: Apr 08, 2004
Posts: 1300
posted
Jul 10, 2011 20:42:40
0
How to compare OS command pwd with
String
value in Shell Script ?
cudir=pwd
if [ "$cudir" == "etc" ]; then
echo "You are in etc"
else
echo "some other"
fi
Peter Johnson
author
Bartender
Joined: May 14, 2008
Posts: 5536
I like...
posted
Jul 11, 2011 08:57:34
0
I think the first line should be (those are backwards single quotes, or ticks, around pwd):
cudir = `pwd`
JBoss In Action
Andrew Monkhouse
author and jackaroo
Marshal Commander
Joined: Mar 28, 2003
Posts: 10816
25
I like...
posted
Jul 11, 2011 09:46:45
0
And remove the spaces around that first equal sign:
cudir=`pwd`
A more readable solution (and one that allows greater flexibility) is to use the alternate construct:
cudir=$(pwd)
Remember that this will give the path from the root directory. Therefore your if statement will also need to refer to the full directory:
if [ "$cudir" == "/etc" ];then
The Sun Certified Java Developer Exam with J2SE 5:
paper version from Amazon
,
PDF from Apress
, Online reference:
Books 24x7
Personal blog
I agree. Here's the link:
http://aspose.com/file-tools
subject: compare OS command with String value in Shell Script ?
Similar Threads
split function problem in AWK
system.exit
Maximum length of Command Line Argument
how to set classpath
Echo value capture in .sh script
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter