0

Im attempting to create a function that when called it will create as many files as the value of a parameter given. For instance, if I call it :

ejercicio_VI file 4

It will create file1 and file2 and file3 and so on...

This obviously works manually but it seems it does not work correctly within a function.

Why is my function not expanding the filenames correctly?

ejercicio_VI() {
    if [[ $# -ne 2 ]]
    then
        echo "Esta funcion solo acepta dos parametros"
        return 255;
    fi

    if [[ ! $1 =~ ^[a-zA-Z]+$ ]]
    then
        echo "El primer parametro debe ser una string que matchee con esta expresion regular : ^[a-zA-Z]+$"
        echo "Asi no creamos archivos basura :P "
        return 255;
    fi
    if [[ ! $2 =~ ^[1-9]([1-9])?+$ ]]
    then
        echo "El segundo parametro debe ser un numero"
        return 255;
    fi

    touch "$1"{1.."$2"}


}
Matias Barrios
  • 4,674
  • 3
  • 22
  • 49
  • 1
    For your convenience, [ShellCheck](https://shellcheck.net) automatically points out [this issue](https://github.com/koalaman/shellcheck/wiki/SC2051) – that other guy May 31 '18 at 05:13
  • @thatotherguy thanks so much for your response. I thought this issue had to do with the function. Sorry for the duplicate. Ill delete this question then – Matias Barrios May 31 '18 at 14:19

0 Answers0