# Ouvrir un fichier sh avec un fichier bash

**URL:** <https://www.debian-fr.org/t/ouvrir-un-fichier-sh-avec-un-fichier-bash/32543>\
**Category:** Programmation\
**Created:** [Février 21, 2016, 2:28 UTC](https://www.debian-fr.org/t/ouvrir-un-fichier-sh-avec-un-fichier-bash/32543 "2016-02-21T02:28:26Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![pascal\_1212](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/p/a587f6/32.png) [@pascal\_1212](https://www.debian-fr.org/u/pascal_1212)\
**Post date:** [Février 21, 2016, 2:28 UTC](https://www.debian-fr.org/t/ouvrir-un-fichier-sh-avec-un-fichier-bash/32543/1 "2016-02-21T02:28:26Z")

</div>

Salut à tous,  
Je me retrouve avec un prob de débutant apparement.  
En claire :  
J’ai un fichier #!bin/bash qui ouvre mplayer avec zenity dont le contenu est ~ :

```auto
#!/bin/bash
[...]
mplayer -slave -input file=/tmp/music-control une_url
[...]
```

et j’ai un fichier #!bin/sh qui le referme

```auto
#!/bin/sh
[...]
echo 'quit' > /tmp/music-control
[...]
```

Quand je les exécutent dans 2 consoles différentes l’un après l’autre sa fonctionne impec, en revanche j’aimerais que le premier fichier appele le second 😕

J’ai testé qque chose comme :

```auto
exec>quiet-mplayer.sh
```

Dans plusieurs sens et avec plusieurs parammètres, mais nada 😊

Quelqu’un une idée ?  
…

---

<div class="post-metadata">

**Author:** ![MisterFreez](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/m/bb73d2/32.png) [@MisterFreez](https://www.debian-fr.org/u/MisterFreez)\
**Post date:** [Février 21, 2016, 2:28 UTC](https://www.debian-fr.org/t/ouvrir-un-fichier-sh-avec-un-fichier-bash/32543/2 "2016-02-21T02:28:27Z")

</div>

Tu devrait pouvoir le faire simplement avec son chemin :

```auto

```

---

<div class="post-metadata">

**Author:** ![pascal\_1212](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/p/a587f6/32.png) [@pascal\_1212](https://www.debian-fr.org/u/pascal_1212)\
**Post date:** [Février 21, 2016, 2:28 UTC](https://www.debian-fr.org/t/ouvrir-un-fichier-sh-avec-un-fichier-bash/32543/3 "2016-02-21T02:28:27Z")

</div>

Hi MisterFreez  
C’est la première chose que j’ai fait, ben nada !  
J’ai controlé les logs histoir de voir si j’avais une erreur, ben re nada !  
Une autre piste ?  
…

---

<div class="post-metadata">

**Author:** ![Arthur](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/a/958977/32.png) [@Arthur](https://www.debian-fr.org/u/Arthur)\
**Post date:** [Février 21, 2016, 2:28 UTC](https://www.debian-fr.org/t/ouvrir-un-fichier-sh-avec-un-fichier-bash/32543/4 "2016-02-21T02:28:27Z")

</div>

Et avec:

```auto

```

Ça donne quoi?

---

<div class="post-metadata">

**Author:** ![MisterFreez](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/m/bb73d2/32.png) [@MisterFreez](https://www.debian-fr.org/u/MisterFreez)\
**Post date:** [Février 21, 2016, 2:28 UTC](https://www.debian-fr.org/t/ouvrir-un-fichier-sh-avec-un-fichier-bash/32543/5 "2016-02-21T02:28:41Z")

</div>

[quote=“pascal\_1212”]Hi MisterFreez  
C’est la première chose que j’ai fait, ben nada !  
J’ai controlé les logs histoir de voir si j’avais une erreur, ben re nada !  
Une autre piste ?  
…[/quote]  
Tu as mis le chemin (au moins relatif) vers l’autre script ?  
Sinon il dis quoi avec #!/usr/bin/bash -x ?

---

<div class="post-metadata">

**Author:** ![pascal\_1212](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/p/a587f6/32.png) [@pascal\_1212](https://www.debian-fr.org/u/pascal_1212)\
**Post date:** [Février 21, 2016, 2:28 UTC](https://www.debian-fr.org/t/ouvrir-un-fichier-sh-avec-un-fichier-bash/32543/6 "2016-02-21T02:28:44Z")

</div>

MisterFreez,  
Je connaissais pas le -x !  
Voilà ce qui ce passe dans la console durant l’exécution et qui s’arrête:

```auto
+ fct_radio
++ zenity --width 320 --height 480 '--title=Les radios On-Line' '--text=Menu Radio' --list --radiolist --column=Choix --column=Radio TRUE RSR_1 FALSE Espace_2 FALSE Sortir
+ radio=RSR_1
+ case $radio in
+ echo 'message:Tu écoutes RSR la 1er'
+ zenity --notification --listen --window-icon=/home/pascal/icones/rsr_1.gif
+ fct_radio1
++ mplayer -slave -input file=/tmp/music-control http://broadcast.infomaniak.ch/rsr-la1ere-high.mp3 -idle
++ zenity --width 320 --height 240 --title=Changer/arreter '--text=Menu Radio' --list --radiolist --column=Choix --column=Actions TRUE Changer FALSE Quitter
Couldn't resolve name for AF_INET6: broadcast.infomaniak.ch
[pulse] working around probably broken pause functionality,
        see http://www.pulseaudio.org/ticket/440
+ radio1=Changer
```

Et quand je start le script externe :

```auto
+ MPlayer UNKNOWN-4.4.1 '(C)' 2000-2009 MPlayer Team Playing http://broadcast.infomaniak.ch/rsr-la1ere-high.mp3. Resolving broadcast.infomaniak.ch for AF_INET6... Resolving broadcast.infomaniak.ch for AF_INET... Connecting to server 'broadcast.infomaniak.ch[84.16.67.133]:' 80... Name : RSR La $'Premi\350re' Genre : public radio Website: http://www.rsr.ch Public : yes Bitrate: 128kbit/s Cache size set to 320 KBytes $'\rCache' fill: 0.00% '(0' 'bytes)' ICY Info: 'StreamTitle='\''Zone' franche- Des sifflets pour 'l'\''arbitre'\'';' $'\rCache' fill: 17.50% '(57344' 'bytes)' Audio only file format detected. ========================================================================== Opening audio decoder: '[mp3lib]' MPEG layer-2, layer-3 AUDIO: 44100 Hz, 2 ch, s16le, 128.0 kbit/9.07% '(ratio:' '16000->176400)' Selected audio codec: '[mp3]' afm: mp3lib '(mp3lib' MPEG layer-2, 'layer-3)' ========================================================================== ICY Info: 'StreamTitle='\''Zone' franche- Des sifflets pour 'l'\''arbitre'\'';' AO: '[pulse]' 44100Hz 2ch s16le '(2' bytes per 'sample)' Video: no video Starting playback... A: 0.0 '(00.0)' of 0.0 '(unknown)' '??,' Exiting... '(Quit)' of 0.0 '(unknown)' 0.3% 40% '
./test_fichier.sh: line 27: 
+ '[' '' == Changer ']'
+ '[' '' == Quitter ']'
```

Bizard cette ligne 27 : MPlayer : commande introuvable pourtant j’ai bien la radio en sortie sur les bafles…

Voilà le script en question :

```auto
#!/bin/bash -x
#find /tmp/music-control
#echo $? 
#echo "==========================="
#if ["/tmp/music-control"]
#then
# echo "le fichier existe :)"
#else
# echo "le fichier existe pas :("
# mkfifo /tmp/music-control
#fi
# mplayer -slave -input file=/tmp/music-control http://broadcast.infomaniak.ch/rsr-espace2-high.mp3 -idle
function fct_radio()
{
        radio=`zenity --width 320 --height 480 --title="Les radios On-Line" --text="Menu Radio" --list --radiolist --column="Choix" --column="Radio" TRUE "RSR_1" FALSE "Espace_2" FALSE "Sortir"`
}
function fct_radio1()
        {
                radio1=`zenity --width 320 --height 240 --title="Changer/arreter" --text="Menu Radio" --list --radiolist --column="Choix" --column="Actions" TRUE "Changer" FALSE "Quitter"`
        }

fct_radio

case $radio in #case du menu radio
                        RSR_1) 
                                echo message:"Tu écoutes RSR la 1er" | zenity --notification --listen --window-icon="/home/$USER/icones/rsr_1.gif" #info-bulle
                                fct_radio1 | `mplayer -slave -input file=/tmp/music-control http://broadcast.infomaniak.ch/rsr-la1ere-high.mp3 -idle`
                                        #ce qui suit (Changer/Quitter), j'aurai pu en faire une fonction :)
                                if ["$radio1" == Changer] #si on veut changer de canal
                                then
                                        echo 'quit' > /tmp/music-control
                                        echo "cliqué sur changer!"
# sh "quiet-mplayer.sh"
# echo "./quiet-mplayer.sh" #exec 6>&1
# sh quiet-mplayer.sh
# ./quiet-mplayer.sh
                                        fct_radio
                                fi
                                if ["$radio1" == Quitter] #si on veut revenir au menu principal
                                then
# fct_input
                                        exit
                                fi 
                                ;;
                        Sortir) #retour au menu principal
# fct_input
                                exit
                        ;;
esac
```

Le script d’arrêt :

```auto
#!/bin/bash
# Quitte mplayer
echo 'quit' > /tmp/music-control
exit 0
```

Vous noterez que j’ai testé plusieurs issus 😕

Je comprends pas si je lance la ligne :

```auto
mplayer -slave -input file=/tmp/music-control http://broadcast.infomaniak.ch/rsr-la1ere-high.mp3 -idle
```

dans une console et que je quitte en appelant ./quiet-mplayer.sh dans une autre y a aucune erreur…

Une idée ?  
…

---

<div class="post-metadata">

**Author:** ![MisterFreez](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/m/bb73d2/32.png) [@MisterFreez](https://www.debian-fr.org/u/MisterFreez)\
**Post date:** [Février 21, 2016, 2:28 UTC](https://www.debian-fr.org/t/ouvrir-un-fichier-sh-avec-un-fichier-bash/32543/7 "2016-02-21T02:28:46Z")

</div>

```auto
Enlève les `. Parce que sinon ça veut dire que tu exécute mplayer puis que tu tente d'évaluer sa sortie comme si c'était du code d'un script shell.
```

Enlève les `. Parce que sinon ça veut dire que tu exécute mplayer puis que tu tente d’évaluer sa sortie comme si c’était du code d’un script shell.

---

<div class="post-metadata">

**Author:** ![pascal\_1212](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/p/a587f6/32.png) [@pascal\_1212](https://www.debian-fr.org/u/pascal_1212)\
**Post date:** [Février 21, 2016, 2:28 UTC](https://www.debian-fr.org/t/ouvrir-un-fichier-sh-avec-un-fichier-bash/32543/8 "2016-02-21T02:28:57Z")

</div>

Ok MisterFreez,  
Après le delete des (`) la console crie moins.  
Voilà ma sortie console :

> [@](#):
>
> - fct\_radio  
> ++ zenity --width 320 --height 480 ‹&nbsp;–title=Les radios On-Line&nbsp;› ‹&nbsp;–text=Menu Radio&nbsp;› --list --radiolist --column=Choix --column=Radio TRUE RSR\_1 FALSE Espace\_2 FALSE Sortir
> - radio=RSR\_1
> - case $radio in
> - echo ‹&nbsp;message:Tu écoutes RSR la 1er&nbsp;›
> - zenity --notification --listen --window-icon=/home/pascal/icones/rsr\_1.gif
> - fct\_radio1
> - mplayer -slave -input file=/tmp/music-control [broadcast.infomaniak.ch/rsr-la1ere-high.mp3](http://broadcast.infomaniak.ch/rsr-la1ere-high.mp3) -idle  
> ++ zenity --width 320 --height 240 --title=Changer/arreter ‹&nbsp;–text=Menu Radio&nbsp;› --list --radiolist --column=Choix --column=Actions TRUE Changer FALSE Quitter  
> MPlayer UNKNOWN-4.4.1 (C) 2000-2009 MPlayer Team
> 
> # Playing [broadcast.infomaniak.ch/rsr-la1ere-high.mp3](http://broadcast.infomaniak.ch/rsr-la1ere-high.mp3). Resolving broadcast.infomaniak.ch for AF\_INET6… Couldn’t resolve name for AF\_INET6: broadcast.infomaniak.ch Resolving broadcast.infomaniak.ch for AF\_INET… Connecting to server broadcast.infomaniak.ch[84.16.67.133]: 80… Name : RSR-La Premiere Public : yes Bitrate: 128kbit/s Cache size set to 320 KBytes Cache fill: 0.00% (0 bytes) ICY Info: StreamTitle=‹&nbsp;Sport Premi�re&nbsp;›; Cache fill: 15.00% (49152 bytes) Audio only file format detected.
> 
> # Opening audio decoder: [mp3lib] MPEG layer-2, layer-3 AUDIO: 44100 Hz, 2 ch, s16le, 128.0 kbit/9.07% (ratio: 16000-\>176400) Selected audio codec: [mp3] afm: mp3lib (mp3lib MPEG layer-2, layer-3)
> 
> [pulse] working around probably broken pause functionality,  
> see [pulseaudio.org/ticket/440](http://www.pulseaudio.org/ticket/440)  
> AO: [pulse] 44100Hz 2ch s16le (2 bytes per sample)  
> Video: no video  
> Starting playback…
> 
> - radio1=Changerof 0.0 (unknown) 0.3% 40%  
> ^C 18.5 (18.4) of 0.0 (unknown) 0.3% 39%
> 
> MPlayer interrupted by signal 2 in module: enable\_cache
> 
> MPlayer interrupted by signal 2 in module: play\_audio  
> A: 18.7 (18.6) of 0.0 (unknown) 0.3% 38%  
> Exiting… (Quit)
> 
> - ‹&nbsp;[&nbsp;› ‹&nbsp;&nbsp;› == Changer ‹&nbsp;]&nbsp;›
> - ‹&nbsp;[&nbsp;› ‹&nbsp;&nbsp;› == Quitter ‹&nbsp;]&nbsp;›  
> toto@mtata:~/zenity$ ^C

Note la ligne + radio1=Changer

On dirait que mon clique sur changer est interprété mais il s’arrête et ne lit plus le reste…

```auto
RSR_1)
echo message:"Tu écoutes RSR la 1er" | zenity --notification --listen --window-icon="/home/$USER/icones/rsr_1.gif" #info-bulle
                                fct_radio1 | mplayer -slave -input file=/tmp/music-control http://broadcast.infomaniak.ch/rsr-la1ere-high.mp3 -idle
                                if ["$radio1" == Changer] #si on veut changer de canal
                                then
# echo "-quit" > /tmp/music-control
                                        echo "cliqué sur changer!"
# sh "quiet-mplayer.sh"
# echo "./quiet-mplayer.sh"
                                        sh quiet-mplayer.sh
# ./quiet-mplayer.sh
                                        fct_radio
                                fi
                                if ["$radio1" == Quitter] #si on veut revenir au menu principal
                                then
# fct_input
                                        exit
                                fi
                                ;;
```

Note que dans la sortie console mon echo «&nbsp;cliqué sur changer!&nbsp;» reste muet 😕

J’avoue plus savoir ![:108](https://www.debian-fr.org/uploads/default/original/1X/08429d01f54fb389a5bb2c12c142516b8d0fc6ba.gif "adr-ag")  
…

---

<div class="post-metadata">

**Author:** ![MisterFreez](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/m/bb73d2/32.png) [@MisterFreez](https://www.debian-fr.org/u/MisterFreez)\
**Post date:** [Février 21, 2016, 2:28 UTC](https://www.debian-fr.org/t/ouvrir-un-fichier-sh-avec-un-fichier-bash/32543/9 "2016-02-21T02:28:58Z")

</div>

radio1 n’est pas initialisé.

Pourquoi tu fais ça ?

```auto

```

---

<div class="post-metadata">

**Author:** ![pascal\_1212](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/p/a587f6/32.png) [@pascal\_1212](https://www.debian-fr.org/u/pascal_1212)\
**Post date:** [Février 21, 2016, 2:29 UTC](https://www.debian-fr.org/t/ouvrir-un-fichier-sh-avec-un-fichier-bash/32543/10 "2016-02-21T02:29:05Z")

</div>

Re MisterFreez,  
Ben quand je veux changer d’url radio, me faut un focus sur un intérupteur. Le but étant d’utiliser une zapette.  
Maintenant, je pourrait re afficher le menu radio.  
Mais y a un truc qui m’échappe !  
Si ma $case est :

```auto
RSR_1)
                                echo message:"Tu écoutes RSR la 1er" | zenity --notification --listen --window-icon="/home/$USER/icones/rsr_1.gif" #info-bulle
# fct_radio1 | mplayer -slave -input file=/tmp/music-control http://broadcast.infomaniak.ch/rsr-la1ere-high.mp3 -idle
                                fct_radio1
# mplayer -slave -input file=/tmp/music-control http://broadcast.infomaniak.ch/rsr-la1ere-high.mp3 -idle 
                                if ["$radio1" == "Changer"] #si on veut changer de canal
                                then
                                        echo "cliqué sur changer!"
                                        echo "-quit > /tmp/music-control"
# ./quiet-mplayer.sh
                                        fct_radio
                                fi
                                if ["$radio1" == Quitter] #si on veut revenir au menu principal
                                then
                                        exit
                                fi
                                ;;
```

Note la ligne 3. Je devrais initialiser ma fonction et mplayer en même temps ?!? Visiblement c’est pas le cas !  
Alors je tente de la décomposer ligne 4, là elle s’exécute jusqu’au bout.  
Mais si j’intercale mplayer, là sa fonctionne plus 😕  
J’ai essayé avec |, &&, même des trucs exotiques, nada.  
WHY ? 😊  
…

---

<div class="post-metadata">

**Author:** ![pascal\_1212](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/p/a587f6/32.png) [@pascal\_1212](https://www.debian-fr.org/u/pascal_1212)\
**Post date:** [Février 21, 2016, 2:29 UTC](https://www.debian-fr.org/t/ouvrir-un-fichier-sh-avec-un-fichier-bash/32543/11 "2016-02-21T02:29:55Z")

</div>

Re à tous,  
Bon là je suis un boulet ![:116](https://www.debian-fr.org/uploads/default/original/1X/eae5ac515968d1af3d7141407139e6921afb85d3.gif "heu!")  
C’est un simple & et non un | ou &&.

```auto
mplayer -slave -input file=/tmp/music-control http://broadcast.infomaniak.ch/rsr-la1ere-high.mp3 -idle & fct_radio1
```

Voilà, y pas plus c\*\*  
Dans tous les cas, merci à tous.
