#!/bin/bash
branch=""
function 3bra(){
#If there's no paramether
if [[ -z "$*" ]]; then
#show me the branches
git branch
#wait for input and give the paramether such entered value
echo "Which branch?"
read -t 10 branch || exit
else
#Stuff to do if 3bra is called with params...
branch="$1"
fi
#checkout to the paramether branch
git checkout "$branch"
if [[ "$?" -eq 0 ]]; then
#if there are no errors, complete the checkout process
npm i
npm rebuild node-sass --force
npm run start
fi
}
#Call the function and pass in the parameters.
3bra "$1"
O read -t 10
especifica um tempo limite de 10 segundos. Se nenhuma entrada for fornecida, o script sai.
Supondo que há outras coisas neste script, caso contrário você não precisaria realmente da chamada de função. Salve o script e execute-o, passando em um argumento. Ele encaminhará o argumento para a função, se presente.
Além disso, eu não estou familiarizado com o git, então se algo git releated está preso no lugar errado, bem, meu mal.