1. Weiterleitung zu NetzLiving.de
  2. Forum
    1. Unerledigte Themen
  3. zum neuen Forum
  • Anmelden
  • Suche
Dieses Thema
  • Alles
  • Dieses Thema
  • Dieses Forum
  • Seiten
  • Forum
  • Erweiterte Suche
  1. Informatik Forum
  2. Webmaster & Internet
  3. Entwicklung

Execute command stored in variable

  • RomanW
  • 23. Juni 2008 um 13:19
  • Unerledigt
Hallo zusammen,

das Informatik-Forum geht in den Archivmodus, genaue Informationen kann man der entsprechenden Ankündigung entnehmen. Als Dankeschön für die Treue bekommt man von uns einen Gutscheincode (informatikforum30) womit man bei netzliving.de 30% auf das erste Jahr sparen kann. (Genaue Infos sind ebenfalls in der Ankündigung)

Vielen Dank für die Treue und das Verständnis!
  • RomanW
    Punkte
    65
    Beiträge
    9
    • 23. Juni 2008 um 13:19
    • #1

    I want to merge many log files (values??.tmp) to one file (values.log):

    e.g. cat values1.tmp values2.tmp >> values.log

    I made this:

    Bash
    #!/bin/bash
    prefix="values"
    suffix=".tmp"
    cmd="cat"
    for i in `seq 1 2`;
    do
      name=$prefix$i$suffix
      cmd=$cmd" "$name
    done    
    cmd=$cmd" >> values.log"
    echo $cmd
    Alles anzeigen

    How to execute $cmd at the prompt as typed?

  • Plantschkuh!
    Punkte
    6.173
    Beiträge
    1.181
    • 23. Juni 2008 um 13:39
    • #2

    This should work:

    Code
    `$cmd`


    (backquotes!) as should this:

    Code
    echo $cmd | xargs
  • RomanW
    Punkte
    65
    Beiträge
    9
    • 23. Juni 2008 um 13:58
    • #3

    Ok, I tried this:

    Bash
    #!/bin/bash
    clear
    prefix="Comps"
    suffix=".tmp"
    cmd="cat"
    for i in `seq 1 2`;
    do
      file=$prefix$i$suffix
      cmd=$cmd" "$file
    done    
    cmd=$cmd" >> Comps_.log"
    #echo $cmd | xargs
    `$cmd`
    Alles anzeigen

    But I get this:

    Code
    cat: >>: No such file or directory
    cat: Comps_.log: No such file or directory
    test.sh: line 13: local: can only be used in a function

    How handling the >> ?

  • Stefan Kögl
    Punkte
    1.010
    Beiträge
    199
    • 23. Juni 2008 um 14:24
    • #4
    Zitat von RomanW


    How handling the >> ?

    You could try `$cmd >> somefile`

  • Kampi
    Punkte
    7.828
    Beiträge
    1.468
    • 23. Juni 2008 um 14:43
    • #5
    Bash
    #!/bin/bash
    prefix="values"
    suffix=".tmp"
    cmd="cat"
    merged="values.log"
    
    
    rm -f $merged
    for i in `seq 1 2`;
    do
      name=$prefix$i$suffix
      $cmd $name >> $merged
    done
    Alles anzeigen

    [edit]
    or at the command prompt:

    Code
    $ cat values?.tmp > values.log

    [/edit]

    Einmal editiert, zuletzt von Kampi (23. Juni 2008 um 14:48)

  • RomanW
    Punkte
    65
    Beiträge
    9
    • 23. Juni 2008 um 15:16
    • #6

    Thanks to Stefan Kögl and Kampi. Both solutions work well!

  • Maximilian Rupp 27. Dezember 2024 um 12:04

    Hat das Thema aus dem Forum Programmieren nach Entwicklung verschoben.

  1. Datenschutzerklärung
  2. Impressum