|
|
|
|
|
|
| Author |
Message |
Kevin Rodgers *nix forums beginner
Joined: 01 Mar 2005
Posts: 29
|
Posted: Fri Feb 18, 2005 4:03 pm Post subject:
Re: Change Environment var and export result only if value contains no "xxxx"?
|
|
|
Matthias Zach wrote:
| Quote: | I could imagine a way similar to
if [ set | grep CLASSPATH | grep "/aaa/bbb/ccc.jar" = "" ] then
export CLASSPATH=/aaa/bbb/ccc.jar:$CLASSPATH
fi
This code above yields a "syntax error at line 234 : 'fi' unexpected.
Why? |
Because the then keyword needs to be on a separater line, or preceded by
a semicolon.
And because the [ ... ] test command expects a single word on each side
of the = operator. You want to compare the output of the set | grep |
grep pipeline to the empty string, so it needs to be enclosed in the
command substitution delimiters.
So:
if [ `set | grep CLASSPATH | grep "/aaa/bbb/ccc.jar"` = "" ]; then
blah blah blah
fi
| Quote: | However, even if it would work I feel that there is a shorter solution.
Is there ?
|
See John L's followup.
--
Kevin Rodgers |
|
| Back to top |
|
 |
John L *nix forums Guru Wannabe
Joined: 17 Mar 2005
Posts: 191
|
Posted: Thu Feb 17, 2005 8:45 pm Post subject:
Re: Change Environment var and export result only if value contains no "xxxx"?
|
|
|
"Matthias Zach" <zach228@fortuencity.com> wrote in message news:cv32c1$jbp$05$1@news.t-online.com...
| Quote: | I want to add a new path /aaa/bbb/ccc,jar to the environment variable CLASSPATH
if and only if it does not contain this jar file yet.
If I have to prepend it it should be exported.
How do I do this the easiest way?
I could imagine a way similar to
if [ set | grep CLASSPATH | grep "/aaa/bbb/ccc.jar" = "" ] then
export CLASSPATH=/aaa/bbb/ccc.jar:$CLASSPATH
fi
This code above yields a "syntax error at line 234 : 'fi' unexpected. Why?
However, even if it would work I feel that there is a shorter solution.
Is there ?
|
case "$CLASSPATH" in
*/aaa/bbb/ccc.jar*) ;;
*) export CLASSPATH="/aaa/bbb/ccc.jar:$CLASSPATH" ;;
esac
--
John. |
|
| Back to top |
|
 |
Matthias Zach *nix forums beginner
Joined: 17 Mar 2005
Posts: 4
|
Posted: Thu Feb 17, 2005 8:29 pm Post subject:
Change Environment var and export result only if value contains no "xxxx"?
|
|
|
I want to add a new path /aaa/bbb/ccc,jar to the environment variable CLASSPATH
if and only if it does not contain this jar file yet.
If I have to prepend it it should be exported.
How do I do this the easiest way?
I could imagine a way similar to
if [ set | grep CLASSPATH | grep "/aaa/bbb/ccc.jar" = "" ] then
export CLASSPATH=/aaa/bbb/ccc.jar:$CLASSPATH
fi
This code above yields a "syntax error at line 234 : 'fi' unexpected. Why?
However, even if it would work I feel that there is a shorter solution.
Is there ?
Peter |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Fri Jan 09, 2009 12:03 am | All times are GMT
|
|
Debt Consolidation | McDonalds | Debt Consolidation | Credit Cards | Problem Mortgage
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|