Reputation: 6255
Either it is late in the day for me or I am missing something naive here.
here is a contrived example
#!/bin/bash
command="ls -al > check.txt"
$command
When I run this script on a shell it gives me error I guess due to the ">" operator. Anyway I can redirect the output from inside a shell script. I thought this was very straight forward:
ls -la > temp.txt
ls: cannot access >: No such file or directory
ls: cannot access temp.txt: No such file or directory
Upvotes: 1
Views: 391
Reputation: 1758
Here is another way to do it using eval
,
#!/bin/bash
command="ls -al > check.txt"
eval $command
Upvotes: 2
Reputation: 25863
#!/bin/bash
command="ls -al"
$command > check.txt
>
is a special character in Bash (and most shells). It does not belong to a command.
Upvotes: 4