Ralf Wildenhues <[EMAIL PROTECTED]> writes:

> +# $FILE_NAME
> +# shell_quote ($FILE_NAME)
> +# ------------------------
> +# If the string $S is a well-behaved file name, simply return it.
> +# If it contains white space, quotes, etc., quote it, and return
> +# the new string.
> +sub shell_quote($)
> +{
> +  my ($s) = @_;
> +  if ($s =~ m![^\w+/.,-]!)
> +    {
> +      # Convert each single quote to '\''
> +      $s =~ s/\'/\'\\\'\'/g;
> +      # Then single quote the string.
> +      $s = "'$s'";
> +    }
> +  return $s;
> +}

A nit: if the goal is to quote only those file names requiring
quoting, then this quotes too often; e.g., it quotes @ in file names.
I think the only characters you should need to worry about in practice
are:

\t \n \r space ! " # $ % & ' ( ) * ; < > ? [ \ ^ ` | ~


Reply via email to