Shell Scripting: Generating output file name in script and then writing to it
Posted
by NewShellScripter
on Stack Overflow
See other posts from Stack Overflow
or by NewShellScripter
Published on 2010-06-03T19:47:26Z
Indexed on
2010/06/03
19:54 UTC
Read the original article
Hit count: 142
shell-scripting
Hello,
I have a shell script where a user passes different sizes as command line arguments. For each of those sizes, I want to perform some task, then save the output of that task into a .txt file with the size in the name.
How can I take the command line passed and make that part of a stringname for the output file? I save the output file in a directory specified by another command line argument. Perhaps an example will clear it up.
In the foor lop, the i value represents the command line argument I need to use, but $$i doesnt work.
./runMe arg1 arg2 outputDir [size1 size2 size3...]
for ((i=4; i<$#; i++ ))
do
ping -s $$i google.com >> $outputDir/$$iresults.txt
done
I need to know how to build the $outputDir/$$iresults.txt string. Also, the ping -s $$i doesnt work. Its like I need two levels of replacement. I need to replace the $[$i] inner $i with the value in the loop, like 4 for ex, making it $4. Then replace $4 with the 4th command line argument!
Any help would be greatly appreciated.
Thanks!
© Stack Overflow or respective owner