Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Bash] String mit Sonderzeichen an Skript übergeben
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
Finswimmer
Bodhisattva
Bodhisattva


Joined: 02 Sep 2004
Posts: 5467
Location: Langen (Hessen), Germany

PostPosted: Thu Jan 29, 2009 8:44 pm    Post subject: [Bash] String mit Sonderzeichen an Skript übergeben Reply with quote

Hallo,

mein Skript erwartet eine URL.
./skript "$url" ---> geht

Nun habe ich aber Programme, denen ich nicht sagen kann, das " " um die URL gehört.
Rufe ich nun
./skript $url
auf, so zerhauts das Ding gar schrecklich.

Wie kann ich der Bash sagen, dass der gesamt String als $1 gelten soll?

Ich hoffe, es ist verständlich.

Danke
Tobi
_________________
Bitte auf Rechtschreibung, korrekte Formatierung und Höflichkeit achten!
Danke
Back to top
View user's profile Send private message
franzf
Advocate
Advocate


Joined: 29 Mar 2005
Posts: 4565

PostPosted: Thu Jan 29, 2009 9:09 pm    Post subject: Reply with quote

Als Workaround kannst du dir doch in ner Schleife alle $# Elemente in eine Variable hängen und damit weiter arbeiten.
Aber das Sonderzeichen-Problem löst das nicht (oder führt ein Sonderzeichen zu einem Leerzeichen, hab das noch nie geschaut...).
Back to top
View user's profile Send private message
blu3bird
Retired Dev
Retired Dev


Joined: 04 Oct 2003
Posts: 614
Location: Munich, Germany

PostPosted: Thu Jan 29, 2009 10:05 pm    Post subject: Re: [Bash] String mit Sonderzeichen an Skript übergeben Reply with quote

Finswimmer wrote:
Wie kann ich der Bash sagen, dass der gesamt String als $1 gelten soll?

Gar nicht, aber du kannst $* benutzen, das sind alle Argumente inklusive Leerzeichen ;)
_________________
Black Holes are created when God divides by zero!
Back to top
View user's profile Send private message
Finswimmer
Bodhisattva
Bodhisattva


Joined: 02 Sep 2004
Posts: 5467
Location: Langen (Hessen), Germany

PostPosted: Thu Jan 29, 2009 10:33 pm    Post subject: Reply with quote

Hmm. Ich merke gerade, dass da auch ne Pipe drin ist. Und damit geht dann wohl gar nix.

Tobi
_________________
Bitte auf Rechtschreibung, korrekte Formatierung und Höflichkeit achten!
Danke
Back to top
View user's profile Send private message
blu3bird
Retired Dev
Retired Dev


Joined: 04 Oct 2003
Posts: 614
Location: Munich, Germany

PostPosted: Thu Jan 29, 2009 11:11 pm    Post subject: Reply with quote

In dem Fall könntest Du einfach xargs vor dein Skript setzen:

Code:
echo $url | xargs ./script

ist dasselbe wie
Code:
./script $url

_________________
Black Holes are created when God divides by zero!
Back to top
View user's profile Send private message
ichbins
n00b
n00b


Joined: 25 Mar 2008
Posts: 40

PostPosted: Sun Feb 01, 2009 2:04 pm    Post subject: Reply with quote

kommen im skript sonst irgendwo " vor !?

wenn nein kannst du doch IFS auf " setzen , oder irre ich mich da?
Back to top
View user's profile Send private message
69719
l33t
l33t


Joined: 20 Sep 2004
Posts: 865

PostPosted: Sun Feb 01, 2009 8:48 pm    Post subject: Reply with quote

Zeig mal den Code von deinem Script, ich vermute dort einen Fehler...
Back to top
View user's profile Send private message
Finswimmer
Bodhisattva
Bodhisattva


Joined: 02 Sep 2004
Posts: 5467
Location: Langen (Hessen), Germany

PostPosted: Sun Feb 01, 2009 9:12 pm    Post subject: Reply with quote

Hier als Beispiel, habe gerade kein Zugriff auf das Skript:
Code:

$cat /tmp/test
#!/bin/bash
echo "$*"


Code:
$bash /tmp/test 12
12

$bash /tmp/test bla|bla|bla
bash: bla: command not found
bash: bla: command not found

$bash /tmp/test "bla|bla|bla"
bla|bla|bla

_________________
Bitte auf Rechtschreibung, korrekte Formatierung und Höflichkeit achten!
Danke
Back to top
View user's profile Send private message
69719
l33t
l33t


Joined: 20 Sep 2004
Posts: 865

PostPosted: Sun Feb 01, 2009 9:23 pm    Post subject: Reply with quote

Ich denke, ich habe etwas falsch verstanden...
Ich dachte du rufst das script auf, aber scheinbar macht es ein Programm und übergibt die URL...
da währe im Script URL=$@ schon richtig.
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