# 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 $_; }