You are not logged in.

#1 22 Jun 2008 07:47

dilemma
Member
Registered: 21 Jun 2008
Posts: 1

Execute command stored in variable

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:

#!/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

How to execute $cmd at the prompt as typed?

Offline

#2 27 Jun 2008 12:34

Simon Sheppard
Admin
Registered: 27 Aug 2005
Posts: 1,130
Website

Re: Execute command stored in variable

I think arithmetic expansion is the easiest way to execute this e.g. your_variable="$(  actual_item_here )"
http://ss64.com/bashsyntax/brackets.html

so try changing the last two lines to this:

cmd="$($cmd >> values.log)"
echo $cmd

Offline

Board footer

Powered by