У меня есть скрипт, который манипулирует текстом и создает файлы в одной директории по имени / аббревиатуре. вот так:
#!/bin/bash
input="$HOME/folha1/it/colaboradores/users.txt"
out="$HOME/folha1/it/colaboradores/LDAP/"
#check if file exist, if exist rewrite for up
while IFS=';' read -r Act Nome Email Numero Skype; do
cat << EOF >> "$out"/"$Act"
Nome: $Nome
Email: $Email
Numero: $Numero
Skype: $Skype
EOF
done < "$input"
но когда я пытаюсь увидеть, есть ли файл, я пробую это
#!/bin/bash
input="$HOME/folha1/it/colaboradores/users.txt"
out="$HOME/folha1/it/colaboradores/LDAP"
if [ "$(ls -A $out)" ]; then
rm -rf $HOME/folha1/it/colaboradores/LDAP/*
fi
while IFS=';' read -r Act Nome Email Numero Skype; do
cat << EOF >> "$out"/"$Act"
Nome: $Nome
Email: $Email
Numero: $Numero
Skype: $Skype
EOF
done < "$input"
, но если у них есть файлы, сценарий на данный момент удаляется, но не создается снова .. и у меня есть эта ошибка:
[teste@oel73 ex02]$ ./ex026.sh
./ex026.sh: line 16: warning: here-document at line 10 delimited by end-of-file (wanted `EOF')
./ex026.sh: line 17: syntax error: unexpected end of file
[teste@oel73 ex02]$
Я не вижу, что не так в скрипте
Я изменяю это:
#!/bin/bash
input="$HOME/folha1/it/colaboradores/users.txt"
out="$HOME/folha1/it/colaboradores/LDAP/"
if [ "$(ls -A $out)" ]; then
rm -rf $HOME/folha1/it/colaboradores/LDAP/*
fi
while IFS=';' read -r Act Nome Email Numero Skype; do
var=$(cat <<-EOF
Nome: $Nome
Email: $Email
Numero: $Numero
Skype: $Skype
EOF
)
echo $var > "$out"/"$Act"
done < "$input"
, но у меня все еще есть:
[teste@oel73 ex02]$ ./ex028.sh
./ex028.sh: line 10: unexpected EOF while looking for matching `)'
./ex028.sh: line 19: syntax error: unexpected end of file
с вашими комментариями я поставил это:
#!/bin/bash
input="$HOME/folha1/it/colaboradores/users.txt"
out="$HOME/folha1/it/colaboradores/LDAP/"
if [ "$(ls -A "$out")" ]; then
rm -rf "$HOME"/folha1/it/colaboradores/LDAP/*
fi
while IFS=';' read -r Act Nome Email Numero Skype; do
cat << EOF >> "$out"/"$Act"
Nome: $Nome
Email: $Email
Numero: $Numero
Skype: $Skype
EOF
done < "$input"