Transpherer un fichier dans un tableau SH
Résolu
felaris
Messages postés
11
Date d'inscription
Statut
Membre
Dernière intervention
-
felaris Messages postés 11 Date d'inscription Statut Membre Dernière intervention -
felaris Messages postés 11 Date d'inscription Statut Membre Dernière intervention -
A voir également:
- Transpherer un fichier dans un tableau SH
- Fichier bin - Guide
- Comment réduire la taille d'un fichier - Guide
- Comment ouvrir un fichier epub ? - Guide
- Tableau word - Guide
- Fichier rar - Guide
12 réponses
Salut,
jp@MDK:~/tmpfs ssh$ cat fich tutu=sdgfsdgfg tata=tutu jhfuyhf=tutu jhfuyhf=tutu KGKGUGIU=lklklk khkl=hfghg kkgkjghk=kjgfuhgf fhjfjhf=jhfhj fhjfjhf=jhfhj toto=tata jp@MDK:~/tmpfs ssh$ cat bar.sh #! /bin/sh #set -xv i=0 while read line do tab[$i]=$line ((i++)) done < fich j=0 while [ "$j" -lt "${#tab[*]}" ] do echo "Element $((j+1)) du tableau : ${tab[$j]}" ((j++)) done jp@MDK:~/tmpfs ssh$ ./bar.sh Element 1 du tableau : tutu=sdgfsdgfg Element 2 du tableau : tata=tutu Element 3 du tableau : jhfuyhf=tutu Element 4 du tableau : jhfuyhf=tutu Element 5 du tableau : KGKGUGIU=lklklk Element 6 du tableau : khkl=hfghg Element 7 du tableau : kkgkjghk=kjgfuhgf Element 8 du tableau : fhjfjhf=jhfhj Element 9 du tableau : fhjfjhf=jhfhj Element 10 du tableau : toto=tata jp@MDK:~/tmpfs ssh$
Je vien de tester, malheureusement j obtient toujours un : permission denied au moment de l ecriture de la ligne dans le tableau.
:s
merci pour ton aide
:s
merci pour ton aide
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
Voici la sortie. Le code est porc mais ca marche jusqu a mon pb. J ai du legerement mof\difier le code que tu m a donner precedement pour cause de syntax error :s
arg1=$1
+ arg1=put
arg2=$2
+ arg2=toto
arg3=$3
+ arg3=tat
op_k_run=0
+ op_k_run=0
op_f_run=0
+ op_f_run=0
op_base_run=0
+ op_base_run=0
error=0
+ error=0
cmd="NULL"
+ cmd=NULL
par1="NULL"
+ par1=NULL
par2="NULL"
+ par2=NULL
table="NULL"
+ table=NULL
error_syntax()
{
echo "Syntax error : Usage : bdsh.sh [-k] [-f <db_file>] (put (<clef> | $<clef>) (<valeur> | $<clef>) |"
echo " del (<clef> | $<clef>) [<valeur> | $<clef>] |"
echo " select [<expr> | $<clef>] )"
echo " flush )"
exit 1
}
error_key()
{
echo "No such key : ..."
exit 1
}
error_base()
{
echo "No base found : file ..."
exit 1
}
do_put()
{
size=$(cat sh.db | wc -l)
size=$((size+1))
echo size:$size
i=0
while read line
do
tab[$i]=$line
i=$((i+1))
done < sh.db
j=0
while [ $j != $size ]
do
echo $tab[$j]
j=$((j+1))
done
# var=$(grep $par1 sh.db)
# line=$(grep $par1 sh.db | wc -l)
# tmp=${var%=*}
# echo TMP:$tmp
# echo $line
#
# if [ $par1 = $tmp ]; then
# {
# echo "rgherherhe"
# }
# else
# {
# echo $par1=$par2 >> sh.db
# }
# fi
exit 0
}
do_del()
{
exit 0
}
do_select()
{
exit 0
}
do_flush()
{
var=""
> sh.db
exit 0
}
ch_param()
{
if [ "put" = $cmd ]; then
do_put
fi
if [ "del" = $cmd ]; then
do_del
fi
if [ "select" = $cmd ]; then
do_select
fi
if [ "flush" = $cmd ]; then
do_flush
fi
echo "verification de param"
}
##################check options
if [ $1 ]; then
{
if [ "-k" = $1 ]; then
op_k_run=1
fi
if [ "-f" = $1 ]; then
op_f_run=1
fi
if [ $2 ] && [ "sh.db" = $2 ]; then
op_base_run=1
fi
if [ "-f" = $2 ]; then
op_f_run=1
fi
if [ $3 ] && [ "sh.db" = $3 ]; then
op_base_run=1
fi
if [ 1 = $op_f_run ] && [ 0 = $op_base_run ]; then
error=1
fi
if [ 0 = $op_f_run ] && [ 1 = $op_base_run ]; then
error=1
fi
if [ $error = 1 ]; then
error_syntax
fi
if [ "-f" != $1 ] && [ "-k" != $1 ] && [ "put" != $1 ] && [ "del" != $1 ] && [ "select" != $1 ] && [ "flush" != $1 ]; then
error_syntax
fi
}
fi
+ [ put ]
+ [ -k = put ]
+ [ -f = put ]
+ [ toto ]
+ [ sh.db = toto ]
+ [ -f = toto ]
+ [ tat ]
+ [ sh.db = tat ]
+ [ 1 = 0 ]
+ [ 0 = 0 ]
+ [ 1 = 0 ]
+ [ 0 = 1 ]
+ [ -f != put ]
+ [ -k != put ]
+ [ put != put ]
###############previous check command
if [ 0 = $op_k_run ] && [ 0 = $op_f_run ]; then
{
if [ $1 ] && [ "select" = $1 ]; then
{
if [ 2 != $# ]; then
error_syntax
else
{
par1=$2
cmd=$1
ch_param
}
fi
}
fi
if [ $1 ] && [ "del" = $1 ]; then
{
if [ 3 != $# ]; then
error_syntax
else
{
par1=$2
cmd=$1
ch_param
}
fi
}
fi
if [ $1 ] && [ "put" = $1 ]; then
{
if [ 3 != $# ]; then
error_syntax
else
{
par1=$2
par2=$3
cmd=$1
ch_param
}
}
fi
}
fi
if [ $1 ] && [ "flush" = $1 ]; then
{
if [ 1 != $# ]; then
error_syntax
else
{
cmd=$1
ch_param
}
fi
}
fi
if [ "put" != $1 ] && [ "del" != $1 ] && [ "select" != $1 ] && [ "flush" != $1 ]; then
error_syntax
fi
}
fi
+ [ 0 = 0 ]
+ [ 0 = 0 ]
+ [ put ]
+ [ select = put ]
+ [ put ]
+ [ del = put ]
+ [ put ]
+ [ put = put ]
+ [ 3 != 3 ]
+ par1=toto
+ par2=tat
+ cmd=put
+ ch_param
+ [ put = put ]
+ do_put
+ cat sh.db
+ wc -l
+ size= 10
+ size=11
+ echo size:11
size:11
+ i=0
+ read line
+ tab[0]=tutu=sdgfsdgfg
tab[0]=tutu=sdgfsdgfg: Permission denied
+ i=1
+ read line
+ tab[1]=tata=tutu
tab[1]=tata=tutu: Permission denied
+ i=2
+ read line
+ tab[2]=jhfuyhf=tutu
tab[2]=jhfuyhf=tutu: Permission denied
+ i=3
+ read line
+ tab[3]=jhfuyhf=tutu
tab[3]=jhfuyhf=tutu: Permission denied
+ i=4
+ read line
+ tab[4]=KGKGUGIU=lklklk
tab[4]=KGKGUGIU=lklklk: Permission denied
+ i=5
+ read line
+ tab[5]=khkl=hfghg
tab[5]=khkl=hfghg: Permission denied
+ i=6
+ read line
+ tab[6]=kkgkjghk=kjgfuhgf
tab[6]=kkgkjghk=kjgfuhgf: Permission denied
+ i=7
+ read line
+ tab[7]=fhjfjhf=jhfhj
tab[7]=fhjfjhf=jhfhj: Permission denied
+ i=8
+ read line
+ tab[8]=fhjfjhf=jhfhj
tab[8]=fhjfjhf=jhfhj: Permission denied
+ i=9
+ read line
+ tab[9]=toto=tata
tab[9]=toto=tata: Permission denied
+ i=10
+ read line
+ j=0
+ [ 0 != 11 ]
+ echo [0]
[0]
+ j=1
+ [ 1 != 11 ]
+ echo [1]
[1]
+ j=2
+ [ 2 != 11 ]
+ echo [2]
[2]
+ j=3
+ [ 3 != 11 ]
+ echo [3]
[3]
+ j=4
+ [ 4 != 11 ]
+ echo [4]
[4]
+ j=5
+ [ 5 != 11 ]
+ echo [5]
[5]
+ j=6
+ [ 6 != 11 ]
+ echo [6]
[6]
+ j=7
+ [ 7 != 11 ]
+ echo [7]
[7]
+ j=8
+ [ 8 != 11 ]
+ echo [8]
[8]
+ j=9
+ [ 9 != 11 ]
+ echo [9]
[9]
+ j=10
+ [ 10 != 11 ]
+ echo [10]
[10]
+ j=11
+ [ 11 != 11 ]
+ exit 0
arg1=$1
+ arg1=put
arg2=$2
+ arg2=toto
arg3=$3
+ arg3=tat
op_k_run=0
+ op_k_run=0
op_f_run=0
+ op_f_run=0
op_base_run=0
+ op_base_run=0
error=0
+ error=0
cmd="NULL"
+ cmd=NULL
par1="NULL"
+ par1=NULL
par2="NULL"
+ par2=NULL
table="NULL"
+ table=NULL
error_syntax()
{
echo "Syntax error : Usage : bdsh.sh [-k] [-f <db_file>] (put (<clef> | $<clef>) (<valeur> | $<clef>) |"
echo " del (<clef> | $<clef>) [<valeur> | $<clef>] |"
echo " select [<expr> | $<clef>] )"
echo " flush )"
exit 1
}
error_key()
{
echo "No such key : ..."
exit 1
}
error_base()
{
echo "No base found : file ..."
exit 1
}
do_put()
{
size=$(cat sh.db | wc -l)
size=$((size+1))
echo size:$size
i=0
while read line
do
tab[$i]=$line
i=$((i+1))
done < sh.db
j=0
while [ $j != $size ]
do
echo $tab[$j]
j=$((j+1))
done
# var=$(grep $par1 sh.db)
# line=$(grep $par1 sh.db | wc -l)
# tmp=${var%=*}
# echo TMP:$tmp
# echo $line
#
# if [ $par1 = $tmp ]; then
# {
# echo "rgherherhe"
# }
# else
# {
# echo $par1=$par2 >> sh.db
# }
# fi
exit 0
}
do_del()
{
exit 0
}
do_select()
{
exit 0
}
do_flush()
{
var=""
> sh.db
exit 0
}
ch_param()
{
if [ "put" = $cmd ]; then
do_put
fi
if [ "del" = $cmd ]; then
do_del
fi
if [ "select" = $cmd ]; then
do_select
fi
if [ "flush" = $cmd ]; then
do_flush
fi
echo "verification de param"
}
##################check options
if [ $1 ]; then
{
if [ "-k" = $1 ]; then
op_k_run=1
fi
if [ "-f" = $1 ]; then
op_f_run=1
fi
if [ $2 ] && [ "sh.db" = $2 ]; then
op_base_run=1
fi
if [ "-f" = $2 ]; then
op_f_run=1
fi
if [ $3 ] && [ "sh.db" = $3 ]; then
op_base_run=1
fi
if [ 1 = $op_f_run ] && [ 0 = $op_base_run ]; then
error=1
fi
if [ 0 = $op_f_run ] && [ 1 = $op_base_run ]; then
error=1
fi
if [ $error = 1 ]; then
error_syntax
fi
if [ "-f" != $1 ] && [ "-k" != $1 ] && [ "put" != $1 ] && [ "del" != $1 ] && [ "select" != $1 ] && [ "flush" != $1 ]; then
error_syntax
fi
}
fi
+ [ put ]
+ [ -k = put ]
+ [ -f = put ]
+ [ toto ]
+ [ sh.db = toto ]
+ [ -f = toto ]
+ [ tat ]
+ [ sh.db = tat ]
+ [ 1 = 0 ]
+ [ 0 = 0 ]
+ [ 1 = 0 ]
+ [ 0 = 1 ]
+ [ -f != put ]
+ [ -k != put ]
+ [ put != put ]
###############previous check command
if [ 0 = $op_k_run ] && [ 0 = $op_f_run ]; then
{
if [ $1 ] && [ "select" = $1 ]; then
{
if [ 2 != $# ]; then
error_syntax
else
{
par1=$2
cmd=$1
ch_param
}
fi
}
fi
if [ $1 ] && [ "del" = $1 ]; then
{
if [ 3 != $# ]; then
error_syntax
else
{
par1=$2
cmd=$1
ch_param
}
fi
}
fi
if [ $1 ] && [ "put" = $1 ]; then
{
if [ 3 != $# ]; then
error_syntax
else
{
par1=$2
par2=$3
cmd=$1
ch_param
}
}
fi
}
fi
if [ $1 ] && [ "flush" = $1 ]; then
{
if [ 1 != $# ]; then
error_syntax
else
{
cmd=$1
ch_param
}
fi
}
fi
if [ "put" != $1 ] && [ "del" != $1 ] && [ "select" != $1 ] && [ "flush" != $1 ]; then
error_syntax
fi
}
fi
+ [ 0 = 0 ]
+ [ 0 = 0 ]
+ [ put ]
+ [ select = put ]
+ [ put ]
+ [ del = put ]
+ [ put ]
+ [ put = put ]
+ [ 3 != 3 ]
+ par1=toto
+ par2=tat
+ cmd=put
+ ch_param
+ [ put = put ]
+ do_put
+ cat sh.db
+ wc -l
+ size= 10
+ size=11
+ echo size:11
size:11
+ i=0
+ read line
+ tab[0]=tutu=sdgfsdgfg
tab[0]=tutu=sdgfsdgfg: Permission denied
+ i=1
+ read line
+ tab[1]=tata=tutu
tab[1]=tata=tutu: Permission denied
+ i=2
+ read line
+ tab[2]=jhfuyhf=tutu
tab[2]=jhfuyhf=tutu: Permission denied
+ i=3
+ read line
+ tab[3]=jhfuyhf=tutu
tab[3]=jhfuyhf=tutu: Permission denied
+ i=4
+ read line
+ tab[4]=KGKGUGIU=lklklk
tab[4]=KGKGUGIU=lklklk: Permission denied
+ i=5
+ read line
+ tab[5]=khkl=hfghg
tab[5]=khkl=hfghg: Permission denied
+ i=6
+ read line
+ tab[6]=kkgkjghk=kjgfuhgf
tab[6]=kkgkjghk=kjgfuhgf: Permission denied
+ i=7
+ read line
+ tab[7]=fhjfjhf=jhfhj
tab[7]=fhjfjhf=jhfhj: Permission denied
+ i=8
+ read line
+ tab[8]=fhjfjhf=jhfhj
tab[8]=fhjfjhf=jhfhj: Permission denied
+ i=9
+ read line
+ tab[9]=toto=tata
tab[9]=toto=tata: Permission denied
+ i=10
+ read line
+ j=0
+ [ 0 != 11 ]
+ echo [0]
[0]
+ j=1
+ [ 1 != 11 ]
+ echo [1]
[1]
+ j=2
+ [ 2 != 11 ]
+ echo [2]
[2]
+ j=3
+ [ 3 != 11 ]
+ echo [3]
[3]
+ j=4
+ [ 4 != 11 ]
+ echo [4]
[4]
+ j=5
+ [ 5 != 11 ]
+ echo [5]
[5]
+ j=6
+ [ 6 != 11 ]
+ echo [6]
[6]
+ j=7
+ [ 7 != 11 ]
+ echo [7]
[7]
+ j=8
+ [ 8 != 11 ]
+ echo [8]
[8]
+ j=9
+ [ 9 != 11 ]
+ echo [9]
[9]
+ j=10
+ [ 10 != 11 ]
+ echo [10]
[10]
+ j=11
+ [ 11 != 11 ]
+ exit 0
Helas non ca ne passe toujours pas.
J ai fait des chmod 777 sur tout mes fichier mais ca change rien
J ai fait des chmod 777 sur tout mes fichier mais ca change rien
hello
/bin/sh sur FreeBSD est-ce du Bourne shell ou du bash ?
le Bourne shell original ne connait pas les tableaux.
/bin/sh sur FreeBSD est-ce du Bourne shell ou du bash ?
le Bourne shell original ne connait pas les tableaux.
c du bourne shell s il connai pas les tableau et n ayant pas le droit a getopt et compagnie je voi pas comment realiser le proj :'(
desoler pour l attente j ai eu quelque souci... passons.
finalement je vai contourner le probleme en passant par un fichier temporaire dans lequel je redirige ce qui m interresse vis a vis de mon fichier sh.db puis ensuite une fois les modifications terminer, je redurige le contenu du fichier temporaire dans le fichier d origine que j aurai au prealable vider puis je supprime le fichier temporaire.
Merci beaucoup pour votre aide.
finalement je vai contourner le probleme en passant par un fichier temporaire dans lequel je redirige ce qui m interresse vis a vis de mon fichier sh.db puis ensuite une fois les modifications terminer, je redurige le contenu du fichier temporaire dans le fichier d origine que j aurai au prealable vider puis je supprime le fichier temporaire.
Merci beaucoup pour votre aide.