Couldnt find the right string" to search for a similar question..so dont know if this has been answered yet...problem is that I want to prepare a command with the requisite parameters passed as a string before executing it...eg: the ls command ..
I can pass "-l", "-t" as parameters and call the generic function as
ls "-l" ## here ls would be the function called and not the generic ls command.
ls "-t"
you don't need to write a function just to perform an ls command : just ls -lt *
I think you problem is more about passing a list of file you want to ls so ...
for i in /etc /usr/var/cron
do
ls -lrt $i
done
or put your list in a file and scan it
[root@lyisy22:~/sand]# cat list
file1
file2
file3
file4
[root@lyisy22:~/sand]# while read f
> do
> ls -l $f
> done<list
Thanks for the early reply..
the ls was just an example...Im trying to modify another command which I have used at about a 100 places in the script...so to make it generic I wanted to write a function..
the command uses parameter a,b,c which perform totally different functions..
The ls command parameters need to be modified instead of the "file" parameters being passed...
Please provide more clues about what doesn't work, with error messages.
There is an extra closing parenthesis, param3 is missing a leading $, the script ending is dubious/truncated.
Why are you escaping the double quotes like this \" ?
Yep, as i said : i post it just as an example. So he is then free to adapt to his needs : add many command into the loop, break line into field stored in variables and so on... stuff that cannot be achieve easily with xargs .
But you are true that in this simple case, xargs is a better way (by the way, i never pretend the contrary)