Skip to content

Inputing values #77

@vitorassis

Description

@vitorassis

I have a .sh script that I made myself but my boss uses Windows, I'd like to rewrite this in batsh but, HOW CAN I READ INPUTS FROM USER?
There's a function for that? I couldn't find any reference for this.

This is the bash code:

#!/bin/bash

echo "Digite a pasta: ";
read dir;

nome="";
for i in $(ls "${dir}"); do
    if [[ ! -d "${dir}/${nome}" || -z $nome ]] ; then
        nome+="${i}";
        if [ ! -d "${dir}/${nome}" ]; then
            nome+=" ";
        fi;
    fi;
    if [ -d "${dir}/${nome}" ] ; then
        nomenovo="";
        for subnome in $nome; do
            if [[ $subnome =~ ^[0-9]+$ ]] ; then
                subnome=$(seq -f "%05g" ${subnome} ${subnome});
            fi
            nomenovo="$nomenovo $subnome";
        done

        echo "NOME ANTIGO: ${nome}"
        echo "NOME NOVO: ${nomenovo}";
        echo
        echo "-------------------"

        cp -r "${dir}/${nome}" "${dir}/${nomenovo}"; 
        nome="";
    fi;
done

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions