rm-r
October 31, 2008, 10:04pm
1
Hi, trying to store a comand involving a redirection in a variable and then run this variable. But the redirection gets lost.
Ex:
#!ksh
MYCMD="ls -l > dirlist.txt"
$MYCMD
This runs the command but displays the result in the terminal instead of redirecting it to the text file.
Can this be done?
MYCMD="ls -l"
$MYCMD > dirlist.txt
MYCMD="ls -l > dirlist.txt"
eval "$MYCMD"
devy
November 2, 2008, 5:01am
4
here's what I'm trying to do:
#!/bin/bash
rootFolder="/cygdrive/d/users/xxx/tmp" #
folders="OutputDir1 OutputDir2 OutputDir3" #
count=0 #
countBcp=0 #
for folder in $folders #
do #
count=`expr $count + 1` #
echo "Folder $count: $folder" #
cd "$rootFolder/$folder" #
pwd #
countBcp="ls -l -d ./bcpFiles* | wc -l" #
eval $countBcp #
i = 0
while $i -lt $countBcp << Problem I can't really compare against $countBcp
do
\# do something
done
done
\#
rm-r
November 3, 2008, 9:50am
5
To Bandit390: Simple and effective - sometimes simple things are just too obvious to be seen.
To cfajohnson: This does the trick. I never used the 'eval' command. I just learned something.
Now my biggest problem is to decide which solution I will use
Thank you very much to both of you.