Re: [bash] Verify substring in shell var
From: Laurent Vogel (lvl_at_club-internet.fr)
Date: 04/30/03
- Next message: Chris F.A. Johnson: "Re: [bash] Verify substring in shell var"
- Previous message: Hyo Joon You: "Re: [bash] Verify substring in shell var"
- In reply to: pt: "[bash] Verify substring in shell var"
- Next in thread: Chris F.A. Johnson: "Re: [bash] Verify substring in shell var"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Wed, 30 Apr 2003 08:35:28 +0200
"pt" <mnemotronic@yahoo.com> a écrit dans le message de news:
da662010.0304292023.51651f77@posting.google.com...
> 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
I doubt your suggestion above works, but a portable way would be
to use 'case':
case $PATH in
*/fred*) ;;
*) PATH=$PATH:/fred ;;
esac
Laurent
- Next message: Chris F.A. Johnson: "Re: [bash] Verify substring in shell var"
- Previous message: Hyo Joon You: "Re: [bash] Verify substring in shell var"
- In reply to: pt: "[bash] Verify substring in shell var"
- Next in thread: Chris F.A. Johnson: "Re: [bash] Verify substring in shell var"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|