Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[solved] Bash-Frage $((
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum
View previous topic :: View next topic  
Author Message
musv
Advocate
Advocate


Joined: 01 Dec 2002
Posts: 3333
Location: de

PostPosted: Fri May 13, 2016 9:03 am    Post subject: [solved] Bash-Frage $(( Reply with quote

Ich hab hier ein Script, bei dem der Vim-Parser meckert und die 2. Klammer rot anzeigt.

Code:
#!/bin/bash

ARCPATH=$((
sudo -u $1 check_config
) | awk '/Ziel/ {print $2} /dest/ {print $3}' )


Auch https://www.shellcheck.net/ schreibt an der Stelle:
Quote:
Line 3:
ARCPATH=$((sudo -u $1 check_config) | awk '/Ziel/ {print $2} /dest/ {print $3}' )
^-- SC1073: Couldn't parse this $((..)) expression.
^-- SC1009: The mentioned parser error was in this $((..)) expression.
^-- SC1072: Fix any mentioned problems and try again.


Füge ich vor die 2. Klammer ein '$' ein, dann klappts, also:
Code:
ARCPATH=$($(sudo …


Was ist jetzt an der Stelle konkret falsch? Das Script funktioniert ja offensichtlich mit beiden Varianten.


Last edited by musv on Fri May 13, 2016 10:59 am; edited 1 time in total
Back to top
View user's profile Send private message
py-ro
Veteran
Veteran


Joined: 24 Sep 2002
Posts: 1734
Location: Velbert

PostPosted: Fri May 13, 2016 9:34 am    Post subject: Reply with quote

Beides ist gültige Syntax und beides ist in dem Beispiel Sinnfrei. Der Parser wird meckern, weil eigentlich "$(())" auch noch mal eine spezielle Syntax ist. Ohne die inneren "()" sollte es immer noch tun.

$() ist == ´´ Wird durch die Ausgabe des Befehls substituiert.
$(( expression )) $(( 5+5 )) wird durch "10" substituiert.
(command ) erzeugt eine Sub-Shell und lässt die Kommandos in den Klammern darin laufen. Im Grunde bash -c 'command'


Bye
Py
Back to top
View user's profile Send private message
musv
Advocate
Advocate


Joined: 01 Dec 2002
Posts: 3333
Location: de

PostPosted: Fri May 13, 2016 10:59 am    Post subject: Reply with quote

Also ein Bug im Vim-Syntaxhighlighting.

Vielen Dank.
Back to top
View user's profile Send private message
py-ro
Veteran
Veteran


Joined: 24 Sep 2002
Posts: 1734
Location: Velbert

PostPosted: Fri May 13, 2016 12:10 pm    Post subject: Reply with quote

Jein, der Token $(( wird halt erwartet, dass es durch )) geschlossen wird.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum