Skip to main content
added 1032 characters in body
Source Link

Also, is there any possible way to get the echo | bc to output a number separated by commas? Some of the numbers can get really large, i.e for random A-Za-z0-9 10 the number of possible combinations is 839299365868340224. I want that to be comma separated so it shows 839,299,365,868,340,224. Full code:

if [ $1 == 'A-Z' ] || [ $1 ==  'a-z' ]
then
    echo "26^$2" | bc 
elif [ $1 == 'A-Za-z' ] || [ $1 ==  'a-zA-Z' ]
then
    echo "52^$2" | bc
elif [ $1 == 'A-Z0-9' ] || [ $1 ==  'a-z0-9' ]
then
    echo "36^$2" | bc
elif [ $1 == 'A-Za-z0-9' ] ||[ $1 == 'a-zA-Z0-9' ]
then
    echo "62^$2" | bc
else
    echo "${#$1}^$2" | bc 

fi
echo "possible combinations"
if [ $# == 2 ]
then
    < /dev/urandom env LC_CTYPE=C tr -dc $1 | head -c $2 | while read -n 1 x 
    do
    printf "\e[1;36m$x"
    sleep 0.03
    done
    echo -e '\033[0m'
    exit 0
exit 1
elif [ $# == 3 ]
then

for (( c=1; c<=$3; c++ ))
 do {
        < /dev/urandom env LC_CTYPE=C tr -dc $1 | head -c $2 | while read -n 1 x 
    do
    printf "\e[0;33m$x"
    sleep 0.03
    done
    echo -e '\033[0m'
}
done


exit 1
fi
  

           

Also, is there any possible way to get the echo | bc to output a number separated by commas? Some of the numbers can get really large, i.e for random A-Za-z0-9 10 the number of possible combinations is 839299365868340224. I want that to be comma separated so it shows 839,299,365,868,340,224.

Also, is there any possible way to get the echo | bc to output a number separated by commas? Some of the numbers can get really large, i.e for random A-Za-z0-9 10 the number of possible combinations is 839299365868340224. I want that to be comma separated so it shows 839,299,365,868,340,224. Full code:

if [ $1 == 'A-Z' ] || [ $1 ==  'a-z' ]
then
    echo "26^$2" | bc 
elif [ $1 == 'A-Za-z' ] || [ $1 ==  'a-zA-Z' ]
then
    echo "52^$2" | bc
elif [ $1 == 'A-Z0-9' ] || [ $1 ==  'a-z0-9' ]
then
    echo "36^$2" | bc
elif [ $1 == 'A-Za-z0-9' ] ||[ $1 == 'a-zA-Z0-9' ]
then
    echo "62^$2" | bc
else
    echo "${#$1}^$2" | bc 

fi
echo "possible combinations"
if [ $# == 2 ]
then
    < /dev/urandom env LC_CTYPE=C tr -dc $1 | head -c $2 | while read -n 1 x 
    do
    printf "\e[1;36m$x"
    sleep 0.03
    done
    echo -e '\033[0m'
    exit 0
exit 1
elif [ $# == 3 ]
then

for (( c=1; c<=$3; c++ ))
 do {
        < /dev/urandom env LC_CTYPE=C tr -dc $1 | head -c $2 | while read -n 1 x 
    do
    printf "\e[0;33m$x"
    sleep 0.03
    done
    echo -e '\033[0m'
}
done


exit 1
fi
  

           
Source Link

How to make this `echo | bc` output be on the same line as the echo output after?

I'm making a program for generating random numbers, and before it generates, I want to show how many combinations there are. When I do it, I get this:

64k@conroe$ bash random A-Za-z0-9 3
238328
possible combinations
CG1

I want 'possible combinations' to be on the same line as '238328', so I get

238328 possible combinations

Here's the code for said section:

if [ $1 == 'A-Z' ] || [ $1 ==  'a-z' ]
then
    echo "26^$2" | bc 
elif [ $1 == 'A-Za-z' ] || [ $1 ==  'a-zA-Z' ]
then
    echo "52^$2" | bc
elif [ $1 == 'A-Z0-9' ] || [ $1 ==  'a-z0-9' ]
then
    echo "36^$2" | bc
elif [ $1 == 'A-Za-z0-9' ] ||[ $1 == 'a-zA-Z0-9' ]
then
    echo "62^$2" | bc
else
    echo "${#$1}^$2" | bc 

fi
echo "possible combinations"

If there's any way to make this shorter as well, I would love to get suggestions. I'm still relatively new to bash scripting.

Also, is there any possible way to get the echo | bc to output a number separated by commas? Some of the numbers can get really large, i.e for random A-Za-z0-9 10 the number of possible combinations is 839299365868340224. I want that to be comma separated so it shows 839,299,365,868,340,224.