[bash] Verify substring in shell var
From: pt (mnemotronic_at_yahoo.com)
Date: 04/30/03
- Next message: Pavol Juhas: "Re: why global variable is lost in sh ?"
- Previous message: Stephane CHAZELAS: "Re: detect if background process in ksh"
- Next in thread: Hyo Joon You: "Re: [bash] Verify substring in shell var"
- Reply: Hyo Joon You: "Re: [bash] Verify substring in shell var"
- Reply: Laurent Vogel: "Re: [bash] Verify substring in shell var"
- Reply: Chris F.A. Johnson: "Re: [bash] Verify substring in shell var"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: 29 Apr 2003 21:23:18 -0700
I'm trying to verify that a shell variable (PATH) contains a directory
and, if not, add it to PATH. I've seen:
if ! echo $PATH | /bin/grep -q "/fred" ; then
PATH=$PATH:/fred
fi
but it occurs to me I might be able to do something like this:
if [[ $PATH != */fred* ]]; then
PATH=$PATH:/fred
fi
Is there any argument for either method (or any six other ways to do
the same thing)? Any reason to do it entirely "within" the shell vs.
via external executables (like "grep")?
- Next message: Pavol Juhas: "Re: why global variable is lost in sh ?"
- Previous message: Stephane CHAZELAS: "Re: detect if background process in ksh"
- Next in thread: Hyo Joon You: "Re: [bash] Verify substring in shell var"
- Reply: Hyo Joon You: "Re: [bash] Verify substring in shell var"
- Reply: Laurent Vogel: "Re: [bash] Verify substring in shell var"
- Reply: Chris F.A. Johnson: "Re: [bash] Verify substring in shell var"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]