syntax error syntax error near unexpected token `done - linux

the script works but I do not understand it when the script has finished the error appears
is my big code with a syntax error near unexpected token `done'
#!/bin/bash
# Function Definition
function process_video {
python vid-xml-decoder/ultimate.py $1
repExport="./export/"
find . -name "*.flv" | while read line
do
name="$(basename "${line}" .flv)"
echo "${name}"
ffmpeg -i "${name}.flv" -vcodec copy -acodec copy mkvtemp.mkv
mkvmerge -v -o "${repExport}${name}.mkv" --default-track 0 --language 0:fre "${name}.ass" mkvtemp.mkv && \
rm -rf "${name}".flv "${name}".ass mkvtemp.mkv
done
}
# Bash Menu
clear
echo "dl master"
PS3='entrez votre chois: '
options=("Creation du cookies.txt" "Téléchargement de la video" "Quit")
select opt in "${options[#]}"
do
case $opt in
"Creation du cookies.txt")
python vid-xml-decoder/login.py 1$
break
;;
"Téléchargement de la video")
read -p "entrer Liens Video ou chemin/nom d'un fichier contenant des liens:" vid
if [[ -e $vid ]] ; then
while read Line
do
process_video $Line
done < $vid
else
process_video $vid
fi
break
;;
"Quit")
break
;;
*) echo invalid option;;
esac
done
this is the error that the script gives me all the end
startdl.sh: line 57: ac: command not found
startdl.sh: line 58: syntax error near unexpected token `done'
startdl.sh: line 58: `done'

Try:
*) echo "invalid option"
;;

Related

Why my code don't understand when I close the for loop?

I am writing a code in Shell Script trying to automatize some procedures in my data processing, but I facing some problems concerning the for. The code is the following. And it seems like he is understanding that I already closed the for loop.
#!/bin/bash
#modelos que serão usados
models=( 410_5x5_nocrust ) # 660_5x5_nocrust mtz_2x2_nocrust mtz_5x5_nocrust mtz_8x8_nocrust mtz_11x11_nocrust prem_nocrust prem s40rts_nocrust 660_5x5_s40rts_nocrust tx2015_nocrust)
#pasta base de onde todos os arquivos e programas estão
home_folder=/home/felipe/sda1_acess/RF_PROCESSING
for i in $models
do
#criando as pastas importantes para o trabalho
if ( ! -e $PWD/Listas )
then
mkdir $PWD/Listas
fi
if ( ! -e $PWD/Listas/"$i"_lists )
then
mkdir $PWD/Listas/"$i"_lists
fi
if ( ! -e $PWD/sacev )
then
mkdir $PWD/sacev
if
if ( ! -e $PWD/sacev/sacev_$i )
then
mkdir $PWD/sacev/sacev_$i/
fi
#setando a pasta onde os arquivos estão
folder=XH_preprocessed_"$i"_stations_1x1_RF_8s
#acessando a pasta
cd $home_folder/$folder
#numero de eventos q temos por modelo
v=(01 02) #03 04 05 06 07 08 09 10 11 12)
#Fazendo as listas
for j in $(v)
do
list=lista_"$i"_"$j".dat
xh_header "$i"_stations_1x1_RF_8s_01"$j"00X.cut.xh -h evnt stat arcs | sort -n -k25 > teste.dat
cat teste.dat | awk '{print $4" "$5" "$6" "$10" "$12" "$13" "$17" "$19" "$25}' | sort -n -k9 > $list
rm teste.dat
for k in $list
do
xh_2sac $PWD/$folder/"$i"_stations_1x1_RF_8s_01"$j"00X.cut.xh -s $k
touch log.dat
echo "r *$k*" > lixo1
echo "chnhdr KT0 'P'" >> lixo1
echo "chnhdr KT1 'Pdiff'" >> lixo1
echo "chnhdr KT2 'S'" >> lixo1
echo "chnhdr KT3 'Sdiff'" >> lixo1
echo "chnhdr KT4 'PcP'" >> lixo1
echo "chnhdr KT5 'PP'" >> lixo1
echo "chnhdr KT6 'SS'" >> lixo1
echo "chnhdr KT7 'P400s'" >> lixo1
echo "chnhdr KT8 'P670s'" >> lixo1
echo "w over" >> lixo1
echo "quit" >> lixo1
sac < lixo1
rm lixo1
done
done
cd $home_folder
mv $home_folder/$folder/lista* $home_folder/Listas/"$i"_lists/
mv $PWD/$folder/*.sac $PWD/sacev/sacev_$i/
#mv $PWD/$folder/log.dat $PWD/sacev/sacev_$i/
mv $PWD/sacev/sacev_$i/ $folder_path
done
the code's name is RFauto and when a do:
bash ./RF
I get the message:
RFauto.sh: row 79: syntax's error next to the unexpected token done' RFauto.sh: row 79: done'
(I had to translate the error massage from portuguese, but I hope it is understandable)
Like I said, he is kinda saying that I already closed the for loop, but when I remove it, it says that I need to close the for loop.
I will be vary grateful for any help!
you need for i in "${models[#]}" to iterate over the elements of the array.
This is correct shell syntax but not what you intend
if ( ! -e $PWD/Listas )
then
mkdir $PWD/Listas
fi
That will attempt to execute the command -e in a subshell and return the exit status negated.
I would expect to see the error "-e: command not found".
You want to use the [[...]] conditional construct
Additionally, mkdir -p will create a directory if it does not exist (including parent directories if they do not exist); if it does exist there is no error
cd $home_folder
mv $home_folder/$folder/lista* $home_folder/Listas/"$i"_lists/
mv $PWD/$folder/*.sac $PWD/sacev/sacev_$i/
#mv $PWD/$folder/log.dat $PWD/sacev/sacev_$i/
mv $PWD/sacev/sacev_$i/ $folder_path
The cd command changed $PWD. Are you sure that's what you want?
In general using $PWD in a program is risky: do you really know the user's location when they invoke the script?
i j k are not very descriptive variable names.
temporary files are usually not necessary.
#!/bin/bash
#modelos que serão usados
models=( 410_5x5_nocrust ) # 660_5x5_nocrust mtz_2x2_nocrust mtz_5x5_nocrust mtz_8x8_nocrust mtz_11x11_nocrust prem_nocrust prem s40rts_nocrust 660_5x5_s40rts_nocrust tx2015_nocrust)
#numero de eventos q temos por modelo
v=(01 02) #03 04 05 06 07 08 09 10 11 12)
#pasta base de onde todos os arquivos e programas estão
home_folder=/home/felipe/sda1_acess/RF_PROCESSING
for i in "${models[#]}"
do
#criando as pastas importantes para o trabalho
mkdir -p "$PWD/Listas/${i}_lists"
mkdir -p "$PWD/sacev/sacev_${i}/"
#setando a pasta onde os arquivos estão
folder="XH_preprocessed_${i}_stations_1x1_RF_8s"
#acessando a pasta
cd "$home_folder/$folder"
#Fazendo as listas
for j in "${v[#]}"
do
list="lista_${i}_${j}.dat"
xh_header "${i}_stations_1x1_RF_8s_01${j}00X.cut.xh" -h evnt stat arcs \
| sort -n -k25 \
| awk '{print $4, $5, $6, $10, $12, $13, $17, $19, $25}' \
| sort -n -k9 \
| while IFS= read -r k
do
xh_2sac "$PWD/$folder/${i}_stations_1x1_RF_8s_01${j}00X.cut.xh" -s "$k"
touch log.dat
sac << END_INPUT
r *$k*
chnhdr KT0 'P'
chnhdr KT1 'Pdiff'
chnhdr KT2 'S'
chnhdr KT3 'Sdiff'
chnhdr KT4 'PcP'
chnhdr KT5 'PP'
chnhdr KT6 'SS'
chnhdr KT7 'P400s'
chnhdr KT8 'P670s'
w over
quit
END_INPUT
done
done
cd "$home_folder"
mv "$home_folder/$folder/lista"* "$home_folder/Listas/${i}_lists/"
mv "$PWD/$folder/"*.sac "$PWD/sacev/sacev_${i}/"
#mv "$PWD/$folder/log.dat" "$PWD/sacev/sacev_${i}/"
mv "$PWD/sacev/sacev_${i}/" "$folder_path"
done

./Backup_date line 20: syntax error near unexpected token `done' ./Backup_Date.sh: line 20: `done'

Write a script that takes a folder as arguments. Your script should compress the files in this folder into a zip file. Your script should:
Check the number of arguments?
Check that the file exists?
Create a Backup_Date.zip file?
Only files belonging to the user, who runs the script, will be compressed
My script is:
#!/bin/bash
dossier=$1
if [[ $# -ne 1 ]] ; then
echo "Err66: Pas de Parametres"
exit 10
fi
DATE=$(date +%Y%m%d)
nomlog="Backup-$DATE.log"
nomFichier="Backup-$DATE.zip"
dossierCourant=`pwd`
ListeFichiers=$(ls -a $dossierCourant)
if [[ ! -d $dossier ]] ; then
echo "Dossier n'existe pas.">> $nomlog
else
zip $nomFichier -C $dossier/$ListeFichiers >> $nomlog
fi
done
When run, I had :
./Backup_Date.sh: line 20: syntax error near unexpected token `done'
./Backup_Date.sh: line 20: `done'
Thank you

syntax error near unexpected token `$'in\r'

when i build shell script am getting the below error, since am new to CentOS am not able to find out the cause can anyone help me regarding this ??
I guess we need to pass command line parameter while executing am not sure what has to be passed as parameter here.
Shell-script :
#!/bin/sh
# Default place to look for apr source. Can be overridden with
# --with-apr=[directory]
apr_src_dir=../apr
while test $# -gt 0
do
# Normalize
case "$1" in
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
*) optarg= ;;
esac
case "$1" in
--with-apr=*)
apr_src_dir=$optarg
;;
esac
shift
done
if test -d "$apr_src_dir"
then
echo ""
echo "Looking for apr source in $apr_src_dir"
else
echo ""
echo "Problem finding apr source in $apr_src_dir."
echo "Use:"
echo " --with-apr=[directory]"
exit 1
fi
# Remove some files, then copy them from apr source tree
rm -f build/apr_common.m4 build/find_apr.m4 build/install.sh \
build/config.guess build/config.sub build/mkdir.sh \
build/make_exports.awk build/make_var_export.awk \
build/get-version.sh
cp $apr_src_dir/build/apr_common.m4 $apr_src_dir/build/find_apr.m4 \
$apr_src_dir/build/install.sh $apr_src_dir/build/config.guess \
$apr_src_dir/build/config.sub $apr_src_dir/build/mkdir.sh \
$apr_src_dir/build/make_exports.awk $apr_src_dir/build/make_var_export.awk \
$apr_src_dir/build/get-version.sh \
build
Error obtained :
[root#localhost apr-iconv]# sh buildconf
buildconf: line 2: $'\r': command not found
buildconf: line 6: $'\r': command not found
buildconf: line 10: syntax error near unexpected token `$'in\r''
'uildconf: line 10: ` case "$1" in
Thank you :)
This error got cleared once shell-script is changed to Unix format. That conversion you can do by executing the command dos2unix <file-name>. If have to install dos2unix to avoid error 'dos2unix: command not found'.

BASH Linux : syntax error « ;; »

i have a syntax error « ;; »
Syntax error near unexpected token « ;; »
my code
#!/bin/bash
# Bash Menu
clear
echo "Decryptor"
PS3='entrez votre chois: '
options=("update" "decryptor" "Quit")
select opt in "${options[#]}"
do
case $opt in
"update")
php updatekey.php
break
;;
"decryptor")
#Nom de la video
read -p "Nom de la série : " name
#detection du fichier .png
find . -name "*.png" | while read line
oname="$(basename "${line}" .png)"
#décryption du fichier png
php -e AES.class.php "${oname}".png
#on change le nom du fichier
mv "${oname}".ass "${name}".ass
read -p "voulez vous télécharger la video (Y/N)? "
[ "$(echo $REPLY | tr [:upper:] [:lower:])" == "y" ] || exit
read -p "entrez liens :" src
read -p "liens vod" vod
rtmpdump -v -T '567ghgh' -r "$vod" -a "vod" -f "WIN 13,0,0,182" -W "http://yoyo.com/components/yoyo.swf" -p "http://yoyo.com" -y "mp4:$src" -o "$name.mp4"
break
;;
"Quit")
break
;;
*) echo invalid option;;
esac
done
is part of code with error
why I get an error I modified the script a bit and this part to not move and I now have an error
What can be the cause
thank you :)
Line 21 contains the beginning of an incomplete while statement. The parser only notices because ;; is illegal when it's still looking for the do.
find stuff | while read line
echo you can have multiple commands here --
echo the exit code of the expression is
echo examined by '"while"'
do
echo ... Body of while loop
done
Your code lacks the do and done parts, and it's unclear to Bash (and to us) where they should go.

linux bash: line 18: syntax error near unexpected token `fi' Q2.sh: line 18: `fi'

I'm trying to compile this code but I am getting the following error:
Q2.sh: line 18: syntax error near unexpected token `fi'
Q2.sh: line 18: `fi'
at line 15, I'm trying to verify if the parameter numero is bigger than 0. Any help is appreciated
Thanks
#!bin/bash
numero=$1
if test $# -eq 0; then
echo "Argument Manquants"
exit 1
fi
if ! [[ "$numero" =~ ^[0-9]+$ ]] ; then
exec >&2; echo "Le parametre doit etre un digit";
exit 1
fi
if [ $numero -le 0 ]
$$ echo "Le parametre doit etre plus grand que 0"
exit 1
fi
cat /etc/passwd grep "$numero"
You forgot the ; then part in your if clause:
if [ "$numero" -le 0 ]; then
...
fi
It looks like you've missed the then statement at the end of your if, and you've only used single square brackets. Try replacing that block for this:
if [[ $numero -le 0 ]]; then
echo "Le parametre doit etre plus grand que 0"
exit 1
fi
I have a similar issue, when i copied the script edited on a windows to unix system. On debut run, I get the same error.
When i edited the file once within the editor on destination m/c, the script ran without issues.
To me it seems to be character encoding issue. But i am still searching for solution for overcoming it in my case.
May be it helps a bit.

Resources