紧缩:bash用其他变量或输入重新运行程序

时间:2017-09-25 22:00:36

标签: bash word-list

我已经编写了一个代码来制作一个单词列表,我想知道如何使用第一个char大写字母运行 $ var1 输入!

基本上我想让第一个char大写,生成两个输出,例如:character1.txt Character2.txt。

进行了一些搜索,但没有找到任何有用的东西,也许我们可以使用If语句或循环来实现它。还不确定!

看看代码:

#!/bin/bash -   
#title          :wordlist_creator.sh
#description    :Feito para ajudar na criação de lista personalizadas direcionadas à alvos precisos.
#author         :Henrique Silva
#date           :2017-09-25
#version        :v2     
#usage          :./wordlist_creator.sh
#notes          :       
#bash_version   :4.4.12(1)-release
#============================================================================

read -p "Digite a letra: " var1

var2=${#var1}

printf "***************************** Adiciona um novo caracter na letra ****************************\n\n*"
var01=$((var2 + 1))
crunch $var01 $var01 -t $var1% -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var01 $var01 -t %$var1 -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var01 $var01 -t $var1^ -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var01 $var01 -t ^$var1 -o Wordlist$(date +'%d-%m-%Y-%s').txt 

printf "***************************** Adiciona 2 novos caracters na letra ****************************\n\n*"
var3=$((var2 + 2))
crunch $var3 $var3 -t $var1%% -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var3 $var3 -t %%$var1 -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var3 $var3 -t $var1^% -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var3 $var3 -t %^$var1 -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var3 $var3 -t $var1^^ -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var3 $var3 -t ^^$var1 -o Wordlist$(date +'%d-%m-%Y-%s').txt 

printf "***************************** Adiciona 3 novos caracters na letra ****************************\n\n*"
var4=$((var2 + 3))
crunch $var4 $var4 -t $var1%%^ -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t $var1%^% -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t $var1^%% -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t $var1^^% -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t $var1^%^ -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t $var1%^^ -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t $var1%%% -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t $var1^^^ -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t %%^$var1 -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t %^%$var1 -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t ^%%$var1 -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t ^^%$var1 -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t ^%^$var1 -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t %^^$var1 -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t %%%$var1 -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t ^^^$var1 -o Wordlist$(date +'%d-%m-%Y-%s').txt 

printf "***************************** data de aniversário em YYYY  ****************************\n\n*"
var5=$((var2 + 4))
crunch $var5 $var5 -t %%%%$var1 -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var5 $var5 -t $var1%%%% -o Wordlist$(date +'%d-%m-%Y-%s').txt 
var6=$((var2 + 5)) 
crunch $var6 $var6 -t %%%%^$var1 -o Wordlist$(date +'%d-%m-%Y-%s').txt 
crunch $var6 $var6 -t $var1^%%%% -o Wordlist$(date +'%d-%m-%Y-%s').txt 

printf "***************************** Aguarde um pouco =D / organizando e juntando os arquvos  ****************************\n\n*"

if [ -d $var1 ]; then
    printf "***************************** Diretório já existe! ****************************\n\n*"   
else
    mkdir -p -v $var1/
fi

cat Wordlist* /usr/share/wordlists/fern-wifi/common.txt /usr/share/wordlists/fasttrack.txt > $var1/$var1-wordlist-$(date +'%d-%m-%Y-%H-sec%S').txt
sleep 10
rm Wordlist*

2 个答案:

答案 0 :(得分:0)

tr,sed和awk可以用来创建一个相同的字符串变量,但第一个字母是大写的,但这里是bash的一种方式:

var1="character1.txt"; var2="${var1^}"

var1: character1.txt
var2: Character1.txt

答案 1 :(得分:0)

完成代码,这就是我用@Philipp Hoehn kingphilippiii给出的内容所做的:

#!/bin/bash -   
#title          :wordlist_creator.sh
#description    :Feito para ajudar na criação de lista personalizadas direcionadas à alvos precisos.
#author         :Henrique Silva
#date           :2017-09-27
#version        :v3     
#usage          :./wordlist_creator.sh
#notes          :       
#bash_version   :4.4.12(1)-release
#============================================================================

read -p "Digite a letra: " input

lnum=${#input} # transforma em números e conta, qtd car//

function mkword_list {

printf "***************************** Adiciona um novo caracter na letra ****************************\n\n*"
var1=$((lnum + 1))
crunch $var1 $var1 -t $input% -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var1 $var1 -t %$input -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var1 $var1 -t $input^ -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var1 $var1 -t ^$input -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 

printf "***************************** Adiciona 2 novos caracters na letra ****************************\n\n*"
var3=$((lnum + 2))
crunch $var3 $var3 -t $input%% -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var3 $var3 -t %%$input -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var3 $var3 -t $input^% -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var3 $var3 -t %^$input -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var3 $var3 -t $input^^ -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var3 $var3 -t ^^$input -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 

printf "***************************** Adiciona 3 novos caracters na letra ****************************\n\n*"
var4=$((lnum + 3))
crunch $var4 $var4 -t $input%%^ -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t $input%^% -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t $input^%% -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t $input^^% -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t $input^%^ -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t $input%^^ -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t $input%%% -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t $input^^^ -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t %%^$input -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t %^%$input -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t ^%%$input -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t ^^%$input -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t ^%^$input -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t %^^$input -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t %%%$input -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var4 $var4 -t ^^^$input -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 

printf "***************************** data de aniversário em YYYY  ****************************\n\n*"
var5=$((lnum + 4))
crunch $var5 $var5 -t %%%%$input -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var5 $var5 -t $input%%%% -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
var6=$((lnum + 5)) 
crunch $var6 $var6 -t %%%%^$input -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 
crunch $var6 $var6 -t $input^%%%% -o W0rdlist$input$(date +'%d-%m-%Y-%s').txt 

} 

mkword_list     # minusculo
input=${input^} 
mkword_list     # maiusculo

printf "***************************** Aguarde um pouco =D / organizando e juntando os arquvos  ****************************\n\n*"

if [ -d $input ]; then
    printf "***************************** Diretório já existe! ****************************\n\n*"   
else
    mkdir -p -v $input/
fi

cat W0rdlist* /usr/share/wordlists/fern-wifi/common.txt /usr/share/wordlists/fasttrack.txt > $input/$input-wordlist-$(date +'%d-%m-%Y-%H-sec%S').txt
sleep 10
rm W0rdlist*