|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
In Shell script, how do I check if a variable contains a :?, there is
something like variable =~ : in Perl, what about in Perl? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On 24 Aug 2006 11:06:27 -0700, yuetwah2000@hotmail.com
<yuetwah2000@hotmail.com> wrote: > In Shell script, how do I check if a variable contains a :?, there is > something like variable =~ : in Perl, what about in Perl? > case $variable in *:\?*) echo yes ;; *) echo no ;; esac -- The major sin is the sin of being born. -- Samuel Beckett |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On 2006-08-24, yuetwah2000@hotmail.com wrote:
> In Shell script, how do I check if a variable contains a :?, there is > something like variable =~ : in Perl, what about in Perl? Use case with filename patterns: case $var in *:*) echo "\$var contains :" ;; *) echo "\$var does not contain :" ;; esac -- Chris F.A. Johnson, author <http://cfaj.freeshell.org> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== and is released under the GNU General Public Licence |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On 24 Aug 2006 11:06:27 -0700, yuetwah2000@hotmail.com wrote:
> In Shell script, how do I check if a variable contains a :?, there is > something like variable =~ : in Perl, what about in Perl? If you want to do perl RE matching, simply do var=FOObar RE='(?i:foo)bar' if perl -e 'exit 1 unless shift =~ shift' "$var" "$RE" then printf '%s matches %s\n" else echo "doesn't match" fi -- Stephane |
|
![]() |
| Outils de la discussion | |
|
|