sub bashquote { "'" . shift =~ s/'/'"'"'/gr . "'" } #### # untested sub bashquote { local $_ = shift; s/'/'"'"'/g; return "'$_'"; } #### # untested sub bashquote { local $_ = shift; defined or die "Argument must not be undef"; /\x00/ and die "String must not contain NUL characters"; s/'/'"'"'/g; return "'$_'"; } #### # untested sub bashquote { local $_ = shift; defined or die "Argument must not be undef"; /\x00/ and die "String must not contain NUL characters"; s/'/'\''/g; return "'$_'"; } #### # untested sub bashquote { local $_ = shift; defined or die "Argument must not be undef"; /\x00/ and die "String must not contain NUL characters"; length or return "''"; s/'/'\''/g; $_ = "'$_'"; s/^''//; s/''$//; return $_; } #### # untested sub bashquote { local $_ = shift; defined or die "Argument must not be undef"; /\x00/ and die "String must not contain NUL characters"; length or return "''"; s/'/'\''/g; s|((?:'\\''){2,})|q{'"} . (q{'} x (length($1) / 4)) . q{"'}|ge; $_="'$_'"; s/^''//; s/''$//; return $_; } #### # untested sub bashquote { local $_ = shift; defined or die "Argument must not be undef"; /\x00/ and die "String must not contain NUL characters"; length or return "''"; # before adding "/" to safe characters: /^[A-Za-z0-9_]+$/ and return $_; m|^[A-Za-z0-9/_]+$| and return $_; s/'/'\''/g; s|((?:'\\''){2,})|q{'"} . (q{'} x (length($1) / 4)) . q{"'}|ge; $_="'$_'"; s/^''//; s/''$//; return $_; } #### # untested sub shell_quote { return join(' ',map { bashquote($_) } @_); }