Reputation: 343
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.
/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
Reputation: 1927
If you need to do this from command line write :
cat sample.txt | tee $str
Upvotes: 2
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