Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inputing values #77

Open
vitorassis opened this issue Feb 11, 2020 · 2 comments
Open

Inputing values #77

vitorassis opened this issue Feb 11, 2020 · 2 comments

Comments

@vitorassis
Copy link

vitorassis commented Feb 11, 2020

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
@oleboleskole3
Copy link

Hi, this should do the trick.

function input(msg) {
    global result;
    result = "";
    print(msg)
    batch("set /p result=");
    bash("read result");
    return result;
}

Just call it, the message is optional.

@javaarchive
Copy link

You're missing a semicolon after print there btw, sorry to bump thread

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants