rameshrgtvl
rameshrgtvl

Reputation: 343

Linux bash Shell scripting : Creating command using string Append how to do that?

Hi I want to achieve #cat sample.txt > abc.txt

But "> abc.txt" am getting as argument.

How to cascade these two strings and execute the combined one.

I tried the below steps

/home/root# export str=" > abc.txt;"    

/home/root# echo $str 

> abc.txt;

/home/root# echo "cat sample.txt $str" 

cat sample.txt  > abc.txt;

/home/root# `echo "cat sample.txt $str"`

Hello world

cat: can't open '>': No such file or directory
cat: can't open 'abc.txt;': No such file or directory

Upvotes: 1

Views: 101

Answers (2)

sestus
sestus

Reputation: 1927

If you need to do this from command line write :

cat sample.txt | tee $str

Upvotes: 2

Deleted User
Deleted User

Reputation: 2541

like this?

#!/bin/bash
args="> foo"
command="date"
eval "$command $args"
cat foo

use of eval is not really a recommended method but sometimes it comes in handy for doing things in a quick and dirty way. I will probably get downrated for suggesting this. Be aware of its side effects.

Upvotes: 2

Related Questions