Brauche Hilfe bei Shell Skript

hermann4

hermann4

Firmware v.3.1
Hallo,

ich möchte ein Skript schreiben, welches mich nur nach einer URL zu einem Video fragt, dieses dann runterlädt und mit mencoder umwandelt.

Praktisch wäre dabei, wenn das Skript sich den Dateinamen für mencoder aus der URL holt, der dort ja nach dem letzten slash steht.

Ist das überhaupt möglich? Ich habe ehrlich gesagt keinen blassen Schimmer wie der Dateiname aus der URL ausgelesen werden könnte

Vielen Dank schonmal

Hermann4
 
Hallo,

ich möchte ein Skript schreiben, welches mich nur nach einer URL zu einem Video fragt, dieses dann runterlädt und mit mencoder umwandelt.
Na dann mach dich an das Werk. ;)
Praktisch wäre dabei, wenn das Skript sich den Dateinamen für mencoder aus der URL holt, der dort ja nach dem letzten slash steht.

Ist das überhaupt möglich? Ich habe ehrlich gesagt keinen blassen Schimmer wie der Dateiname aus der URL ausgelesen werden könnte

Vielen Dank schonmal

Hermann4

Das kommt doch auf die URL an.
Ohne Beispielcode kann man da nix helfen.

Wichtig ist:
Welches OS, welche Shell, wie sehen die Daten aus, was soll rauskommen.

So aus der Kalten würde ich sagen, du verwendest:
wget
sed
mencoder

Schau dir die Manpage dazu an.

Gruß Wolfgang
 
wenn du die URL als argument übergibst, wie du das hier schilderst, dann solltest du das einfach via arg[1] in deinem script rausziehen können ... natürlich hast du dann die gesamte url :) aber strings lassen sich leicht bearbeiten
 
sowas ähnliches gibt es schon. schau dich mal z.B. auf www.kde-apps.org um. vielleicht kannst du, wenn du fähig bist ein bisschen quellcode zu lesen, dort ein paar ideen abstauben?

viel erfolg

tuxlover
 
Also der eigentliche Befehl, der dabei herauskommen sollte sieht etwas so aus

Code:
wget http://url.de/video.mp4 && mencoder video.mp4 [Parameter1,2...]

Dabei sind die Parameter beim mencoder immer gleich

Werde mir mal die manpages von sed ansehen
 
Hallo
Zu der URL ein kleiner Tipp:

Code:
$ U='http://url.de/video.mp4'
 echo ${U##*\/}
video.mp4
 
Hallo
Zu der URL ein kleiner Tipp:

Code:
$ U='http://url.de/video.mp4'
 echo ${U##*\/}
video.mp4

Wenn ich deine Befehle benutze, bekomme ich immer ein video.mp4 als Ausgabe, auch wenn ich es mit "video1.mp4" nutze. Müssen da Parameter geändert werden?
.
.
.
EDIT (autom. Beitragszusammenführung) :
.

Die Eingabe mit U= kenne ich noch gar nicht. Gibt es da so etwas wie einen Cache, den man erst leeren muss?
 
Zuletzt bearbeitet:
U ist eine Variable, die die Beispielurl enthält. Kannst du frei wählen.
Ich nutze hier die Variablenexpansion der bash/ksh.
Du hast leider noch keine Auskunft über die verwendete Shell nebst OS gegeben ,deshalb schreibe ich hier für die bash.

Code:
U='http://url.de/video.mp4'
NAME=${U##*\/}
mencoder $NAME [optionen]
 
Zuletzt bearbeitet:
Sorry ich benutze bash und ein stinknormales Ubuntu
.
.
.
EDIT (autom. Beitragszusammenführung) :
.

Danke Leute, jetzt funktionierts!
 
Zuletzt bearbeitet:
getestet >
Code:
#!/bin/sh
DOWNLOAD='zenity --entry --text "Bitte URL eingeben"`
urxvt -e wget $DOWNLOAD
Wenn du es ausführst, kommt ein eingabe dialog, wo du die url eingebst und auf OK klickst. Dannach downloadet er es.

Urxvt und Zenity benötigt. natürlich kannst irgendein anderen terminal nehmen. Das dient nur dazu um zu gucken wie weit er ist. natürlich kann man das noch mit "zenity --progress" kombinieren. bin aber jetzt zufaul für ;)

Edit: Ups, erst grad gesehn das es schon gelöst ist. naja, so gehts auch ;)
 
Zuletzt bearbeitet von einem Moderator:
U ist eine Variable, die die Beispielurl enthält. Kannst du frei wählen.
Ich nutze hier die Variablenexpansion der bash/ksh.
Du hast leider noch keine Auskunft über die verwendete Shell nebst OS gegeben ,deshalb schreibe ich hier für die bash.

Code:
U='http://url.de/video.mp4'
NAME=${U##*\/}
mencoder $NAME [optionen]

hallo,
beim umwandeln bzw. filtern von variablen-werten über dergleichen Kommandos wie etwa dieser Teil # # * \ / von ${U##*\/} sehe ich, dass diese sehr kryptisch aufgebaut sind. gibt es dazu totorials oder hilfe-seiten? wie nennen sich diese komandos, variablenexpansionen?

string-variablen lassen sich ja auch über sed weiterverarbeiten, die parameter zu sed sind aber ebenfalls sehr kryptisch.

gruß und fohes fest,
w.
 
Zuletzt bearbeitet:
hallo,
beim umwandeln bzw. filtern von variablen-werten über dergleichen Kommandos wie etwa dieser Teil # # * \ / von ${U##*\/} sehe ich, dass diese sehr kryptisch aufgebaut sind. gibt es dazu totorials oder hilfe-seiten? wie nennen sich diese komandos, variablenexpansionen?

string-variablen lassen sich ja auch über sed weiterverarbeiten, die parameter zu sed sind aber ebenfalls sehr kryptisch.

gruß und fohes fest,
w.

Dazu gibt es erstmal lokal Hilfe in der.... ;)
Manpage
Parameter Expansion
The ‘$’ character introduces parameter expansion, command substitution, or arithmetic expansion. The parameter
name or symbol to be expanded may be enclosed in braces, which are optional but serve to protect the variable to
be expanded from characters immediately following it which could be interpreted as part of the name.

When braces are used, the matching ending brace is the first ‘}’ not escaped by a backslash or within a quoted
string, and not within an embedded arithmetic expansion, command substitution, or parameter expansion.

${parameter}
The value of parameter is substituted. The braces are required when parameter is a positional parameter
with more than one digit, or when parameter is followed by a character which is not to be interpreted as
part of its name.

If the first character of parameter is an exclamation point, a level of variable indirection is introduced. Bash
uses the value of the variable formed from the rest of parameter as the name of the variable; this variable is
then expanded and that value is used in the rest of the substitution, rather than the value of parameter itself.
This is known as indirect expansion. The exceptions to this are the expansions of ${!prefix*} and ${!name[@]}
described below. The exclamation point must immediately follow the left brace in order to introduce indirection.

In each of the cases below, word is subject to tilde expansion, parameter expansion, command substitution, and
arithmetic expansion. When not performing substring expansion, bash tests for a parameter that is unset or null;
omitting the colon results in a test only for a parameter that is unset.

${parameter:-word}
Use Default Values. If parameter is unset or null, the expansion of word is substituted. Otherwise, the
value of parameter is substituted.
${parameter:=word}
Assign Default Values. If parameter is unset or null, the expansion of word is assigned to parameter.
The value of parameter is then substituted. Positional parameters and special parameters may not be
assigned to in this way.
${parameter:?word}
Display Error if Null or Unset. If parameter is null or unset, the expansion of word (or a message to
that effect if word is not present) is written to the standard error and the shell, if it is not interac‐
tive, exits. Otherwise, the value of parameter is substituted.
${parameter:+word}
Use Alternate Value. If parameter is null or unset, nothing is substituted, otherwise the expansion of
word is substituted.
${parameter:offset}
${parameter:offset:length}
Substring Expansion. Expands to up to length characters of parameter starting at the character specified
by offset. If length is omitted, expands to the substring of parameter starting at the character speci‐
fied by offset. length and offset are arithmetic expressions (see ARITHMETIC EVALUATION below). length
must evaluate to a number greater than or equal to zero. If offset evaluates to a number less than zero,
the value is used as an offset from the end of the value of parameter. Arithmetic expressions starting
with a - must be separated by whitespace from the preceding : to be distinguished from the Use Default
Values expansion. If parameter is @, the result is length positional parameters beginning at offset. If
parameter is an array name indexed by @ or *, the result is the length members of the array beginning with
${parameter[offset]}. A negative offset is taken relative to one greater than the maximum index of the
specified array. Note that a negative offset must be separated from the colon by at least one space to
avoid being confused with the :- expansion. Substring indexing is zero-based unless the positional param‐
eters are used, in which case the indexing starts at 1.

${!prefix*}
${!prefix@}
Expands to the names of variables whose names begin with prefix, separated by the first character of the
IFS special variable.

${!name[@]}
${!name[*]}
If name is an array variable, expands to the list of array indices (keys) assigned in name. If name is
not an array, expands to 0 if name is set and null otherwise. When @ is used and the expansion appears
within double quotes, each key expands to a separate word.

${#parameter}
The length in characters of the value of parameter is substituted. If parameter is * or @, the value sub‐
stituted is the number of positional parameters. If parameter is an array name subscripted by * or @, the
value substituted is the number of elements in the array.

${parameter#word}
${parameter##word}
The word is expanded to produce a pattern just as in pathname expansion. If the pattern matches the
beginning of the value of parameter, then the result of the expansion is the expanded value of parameter
with the shortest matching pattern (the ‘‘#’’ case) or the longest matching pattern (the ‘‘##’’ case)
deleted. If parameter is @ or *, the pattern removal operation is applied to each positional parameter in
turn, and the expansion is the resultant list. If parameter is an array variable subscripted with @ or *,
the pattern removal operation is applied to each member of the array in turn, and the expansion is the
resultant list.

${parameter%word}
${parameter%%word}
The word is expanded to produce a pattern just as in pathname expansion. If the pattern matches a trail‐
ing portion of the expanded value of parameter, then the result of the expansion is the expanded value of
parameter with the shortest matching pattern (the ‘‘%’’ case) or the longest matching pattern (the ‘‘%%’’
case) deleted. If parameter is @ or *, the pattern removal operation is applied to each positional param‐
eter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with
@ or *, the pattern removal operation is applied to each member of the array in turn, and the expansion is
the resultant list.

${parameter/pattern/string}
${parameter//pattern/string}
The pattern is expanded to produce a pattern just as in pathname expansion. Parameter is expanded and the
longest match of pattern against its value is replaced with string. In the first form, only the first
match is replaced. The second form causes all matches of pattern to be replaced with string. If pattern
begins with #, it must match at the beginning of the expanded value of parameter. If pattern begins with
%, it must match at the end of the expanded value of parameter. If string is null, matches of pattern are
deleted and the / following pattern may be omitted. If parameter is @ or *, the substitution operation is
applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an
array variable subscripted with @ or *, the substitution operation is applied to each member of the array
in turn, and the expansion is the resultant list.
...
Oder Online in diversen Trefffern bei der Suchmaschine deiner Wahl.
Stichwort: Parameter Expansion


Gruß Wolfgang
 
danke für den Tipp. :)
das wird mir helfen.
gruß, w.
 

Ähnliche Themen

Deutsche Installationsanleitung für Slackware 9.0 (und auch 9.1)

Zurück
Oben