Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用bash损坏随机字符字符串_Bash_Shell - Fatal编程技术网

使用bash损坏随机字符字符串

使用bash损坏随机字符字符串,bash,shell,Bash,Shell,我有一根绳子,看起来像 /6435045045/hpdqbhflyuhv_EOlXG 我想通过更改几个字符来损坏字符串。是的 $string | sed 's/E/A/g' 它工作正常,但字符串是动态的,现在生成的字符串中没有“E”。 是否可以使用bash将前x个字符替换为一些随机的x个字符来损坏字符串???>string=“/6435045045/hpdqbhflyuhv\u EOlXG” > string="/6435045045/hpdqbhflyuhv_EOlXG" >

我有一根绳子,看起来像

/6435045045/hpdqbhflyuhv_EOlXG
我想通过更改几个字符来损坏字符串。是的

$string | sed 's/E/A/g' 
它工作正常,但字符串是动态的,现在生成的字符串中没有“E”。 是否可以使用bash将前x个字符替换为一些随机的x个字符来损坏字符串???

>string=“/6435045045/hpdqbhflyuhv\u EOlXG”
> string="/6435045045/hpdqbhflyuhv_EOlXG"
> n=8
> m=`expr ${#string} - $n`
> string="`< /dev/urandom tr -dc A-Za-z0-9_ | head -c$n``echo $string | tail -c$m`"
> echo $string
oZeHdOD_45/hpdqbhflyuhv_EOlXG
>n=8 >m=`expr${#string}-$n` >string=“`dev/uradom tr-dc A-Za-z0-9|head-c$n``echo$string|tail-c$m`” >echo$字符串 Ozehdou\u 45/hpdqbhflyuhv\u EOlXG
您希望如何制作字符串

tr 'A-Za-z' 'N-ZA-Mn-za-m' <<<$string

tr'A-Za-z'-N-Za-Mn-Za-m'这是bash中的一个脚本。它允许您指定字符范围和字符串内容的更改次数

#!/bin/bash

# syntax: corrupt <string> <times> <character range in ascii codes>
#
function corrupt {
    local STRING=$1
    local STRING_LENGTH=${#1}

    local TIMES=$2

    local RANGE=("${@:3}")
    local RANGE_LENGTH="${#RANGE[@]}"

    local CHARS=()
    local C P I=0 IFS=''

    while read -rd $'\0' C; do
        CHARS[I++]=$C
    done < <(echo -ne "$(printf '\\x%x\\x00' "${RANGE[@]}")")

    for (( I = 0; I < TIMES; ++I )); do
        C=${CHARS[RANDOM % RANGE_LENGTH]}
        P=$(( RANDOM % STRING_LENGTH ))
        STRING="${STRING:0:P}${C}${STRING:P + 1}"
    done

    echo "$STRING"

    # Uncomment to save the value to variable __.
    # __=$STRING
}

corrupt "/6435045045/hpdqbhflyuhv_EOlXG" 10 {32..126}
#/bin/bash
#语法:损坏
#
功能腐败{
本地字符串=$1
本地字符串长度=${1}
当地时间=2美元
本地范围=(“${@:3}”)
本地范围_LENGTH=“${#范围[@]}”
本地字符=()
局部C P I=0如果S=''
读取时-rd$'\0'C;执行
字符[I++]=$C
完成<