0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

bash で 英字で始まる英数字を作る

Posted at
# ------------------------------------------------------
# 英字で始まる英数字を echo 
# 第一引数 : 桁数
# ------------------------------------------------------
function        __f_l_mk_ID()
{
        local   T=
        local   B=
        local   C=${1:-8}

        # 数字か?
        printf "%d" $C 2>/dev/null >&2
        [[ $? -ne 0 ]] && return 1

        if [[ $C -gt 1 ]] ; then
                C=$(( C - 1 ))
                T=$(env LANG=C /usr/bin/tr -dc A-Z < /dev/urandom | /usr/bin/head -c 1)
                B=$(env LANG=C /usr/bin/tr -dc A-Z0-9 < /dev/urandom | /usr/bin/head -c $C)
                echo "$T$B"
        fi

        return 0
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?