Linux Bash - erreur de syntaxe fin de fichier prématurée
Résolu
bayano
-
bayano -
bayano -
Bonjour,
j'ai un problème au niveau d'un mini script bash pour envoyer une notifications
j'aimerais savoir pourquoi?
j'ai un problème au niveau d'un mini script bash pour envoyer une notifications
j'aimerais savoir pourquoi?
./notifications.sh: ligne 7: erreur de syntaxe : fin de fichier prématurée
#!/bin/bash cat collaborators.txt|while read collabs do curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "$collabs" http://monserveur/NotifCollaborators done exit
1 réponse
-
Salut,
Peux-tu afficher ton script avec l'option -A de la commande cat :cat -A ton_script
Sinon, il est préférable d'utiliser la syntaxe de redirection plutôt qu'un pipe :#!/bin/bash while read collabs do curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "$collabs" http://monserveur/NotifCollaborators done < collaborators.txt exit
-
> Peux-tu afficher ton script avec l'option -A de la commande cat
$ cat -A notif.sh #!/bin/bash^M$ cat collaborators.txt|while read collabs^M$ do^M$ curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "$collabs" http://monserveur/NotifCollaborators^M$ done^M$ exit^M$
> il est préférable d'utiliser la syntaxe de redirection
Maintenant j'ai cette erreur./notif.sh: ligne 5: erreur de syntaxe près du symbole inattendu « done »
'/notif.sh: ligne 5: `done < collaborators.txt
Synopsis:
Pour envoyer une notification au collaborateur 1curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "&email=collaborator1%40monserveur.tld" http://monserveur/NotifCollaborators
J'ai 15 collaborateurs (15 emails)
avec mon script je veux importer les 15 emails et envoyer 15 notifications.
Alternative:curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "&email=collaborator1%40monserveur.tld" http://monserveur/NotifCollaborators curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "&email=collaborator2%40monserveur.tld" http://monserveur/NotifCollaborators ... .. . curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "&email=collaborator15%40monserveur.tld" http://monserveur/NotifCollaborators
Merci pour votre aide.
-
