Skip to content

Inputing values #77

Open
Open

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

Activity

  1. oleboleskole3 commented on May 26, 2020

    @oleboleskole3

    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.

  2. javaarchive commented on Nov 7, 2020

    @javaarchive

    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

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