Create file from shell

Asked

Viewed 55 times

1

I have a code that I created, and I need it to create a.txt file after the execution that I sent, but it is not doing. Follow code to better understand, I appreciate the help.

#!/usr/bin/env bash
declare -a vetor_arquivos #Declara vetor dos arquivos
grep -R package*  ./Javas *.java > teste.txt #gera um arquivo com todos os arquivos encontrados
mapfile vetor_arquivos < ./teste.txt  #recupera arquivo mapiando para um vetor

for i in "${vetor_arquivos[@]}"; do #Percorre o vetor

    echo $i #printa arquivo encontrando

done
echo "FIM"

It is printing on the terminal screen but does not create the file.

1 answer

1

If you’re talking about this line here :

grep -R package*  ./Javas *.java > teste.txt

He must have created the file, but since you didn’t put the full path he must be somewhere else ...

It is super important to specify the full path of things in bash, I believe you should specify the full path from wherever the file is created, e.g.:

/home/user/teste.txt

I also recommend that you put the full path from where the folder is Javas...

Don’t forget that you also have here mapfile vetor_arquivos < /home/user/teste.txt to change

  • Thanks, it worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.