Re: [bash] Verify substring in shell var

From: Laurent Vogel (lvl_at_club-internet.fr)
Date: 04/30/03


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



Relevant Pages

  • Re: Help with running IBM-COBOL ver 1.0 on Windows 2000/XP
    ... IBM Personal Computer COBOL Compiler ... the byte immediately before this string and verify that it is 01 before ... copies of the files if this suggestion fails. ...
    (comp.lang.cobol)
  • Re: Help with running IBM-COBOL ver 1.0 on Windows 2000/XP
    ... IBM Personal Computer COBOL Compiler ... the byte immediately before this string and verify that it is 01 before ... copies of the files if this suggestion fails. ...
    (comp.lang.cobol)
  • Re: use grep to match newline
    ... > I'm currently use grep to check if a var to verify the following ... > the name are comprised of only alphanumeric characters plus ...
    (comp.unix.shell)
  • Re: Bug in geometry package?
    ... package not working as it should and not as ... I wanted to verify, a lacking of my understanding, then my suggestion ...
    (comp.text.tex)
  • Re: More adventures with Help
    ... Chris Burrows wrote: ... Before making the suggestion did you verify that it is actually a ... IMO a nice candidate for a QC entry. ...
    (borland.public.delphi.non-technical)